Skip to content

Commit

Permalink
Fixes (#27)
Browse files Browse the repository at this point in the history
* aura: genesis + init-script

* aura genesis

* core, params: wip on aura, still not working
  • Loading branch information
holiman authored and priom committed Sep 9, 2018
1 parent e177f52 commit 1743af1
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 74 deletions.
3 changes: 2 additions & 1 deletion aura.genesis
Expand Up @@ -12,7 +12,8 @@
"authorities":[
"0x0082a7bf6aaadab094061747872243059c3c6a07",
"0x00faa37564140c1a5e96095f05466b9f73441e44"],
"difficulty" : 131072
"difficulty" : 131072,
"signatures": ["gA==","uEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACsHcD/7g=="]
}
},
"nonce": "0x0",
Expand Down
2 changes: 1 addition & 1 deletion consensus/aura/aura.go
Expand Up @@ -286,7 +286,7 @@ func (a *Aura) verifyHeader(chain consensus.ChainReader, header *types.Header, p
return errInvalidExtraData
}
// Ensure that the mix digest is zero as we don't have fork protection currently
if header.MixDigest != (common.Hash{}) {
if header.MixDig() != (common.Hash{}) {
return errInvalidMixDigest
}
// Ensure that the block doesn't contain any uncles which are meaningless in PoA
Expand Down
12 changes: 12 additions & 0 deletions core/genesis.go
Expand Up @@ -234,6 +234,8 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
}
}
root := statedb.IntermediateRoot(false)


head := &types.Header{
Number: new(big.Int).SetUint64(g.Number),
Nonce: types.EncodeNonce(g.Nonce),
Expand All @@ -247,12 +249,21 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
Coinbase: g.Coinbase,
Root: root,
}

if g.Config.Aura != nil {
for _, signature := range g.Config.Aura.Signatures {
head.Signatures = append(head.Signatures, signature)
}
}
if g.GasLimit == 0 {
head.GasLimit = params.GenesisGasLimit
}
if g.Difficulty == nil {
head.Difficulty = params.GenesisDifficulty
}
data,_ := rlp.EncodeToBytes(head)
fmt.Printf("Genesis header rlp %v\n", common.Bytes2Hex(data))

statedb.Commit(false)
statedb.Database().TrieDB().Commit(root, true)

Expand Down Expand Up @@ -332,6 +343,7 @@ func DefaultRinkebyGenesisBlock() *Genesis {
Alloc: decodePrealloc(rinkebyAllocData),
}
}

//Need alloc data
// DefaultGoerliGenesisBlock returns the Goerli network genesis block.
func DefaultGoerliGenesisBlock() *Genesis {
Expand Down
163 changes: 143 additions & 20 deletions core/types/block.go
Expand Up @@ -19,6 +19,7 @@ package types

import (
"encoding/binary"
"github.com/ethereum/go-ethereum/params"
"io"
"math/big"
"sort"
Expand Down Expand Up @@ -65,24 +66,46 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
}

//go:generate gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
type AuraHeader struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner" gencodec:"required"`
Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Time *big.Int `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData" gencodec:"required"`
Signature1 []byte `json:"signature1,omitempty"`
Signature2 []byte `json:"signature2,omitempty"`
}

// Header represents a block header in the Ethereum blockchain.
type Header struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner" gencodec:"required"`
Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Time *big.Int `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData" gencodec:"required"`
MixDigest common.Hash `json:"mixHash" gencodec:"required"`
Nonce BlockNonce `json:"nonce" gencodec:"required"`
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner" gencodec:"required"`
Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Time *big.Int `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData" gencodec:"required"`
MixDigest common.Hash `json:"mixHash" gencodec:"required"`
Nonce BlockNonce `json:"nonce" gencodec:"required"`
Signatures params.Signatures `json:"signature,omitempty"`
}

func (h *Header) MixDig() common.Hash {
return common.Hash{}
}

// field type overrides for gencodec
Expand All @@ -96,10 +119,108 @@ type headerMarshaling struct {
Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON
}

// DecodeRLP decodes the Ethereum
func (h *Header) DecodeRLP(s *rlp.Stream) error {

var aura AuraHeader

// Try decoding as aura header first
if err := s.Decode(&aura); err != nil {
return err
//return s.Decode(h)
}
//Aura decoded fine, now convert to header
h.ParentHash = aura.ParentHash
h.UncleHash = aura.UncleHash
h.Coinbase = aura.Coinbase
h.Root = aura.Root
h.TxHash = aura.TxHash
h.ReceiptHash = aura.ReceiptHash
h.Bloom = aura.Bloom
h.Difficulty = aura.Difficulty
h.Number = aura.Number
h.GasLimit = aura.GasLimit
h.GasUsed = aura.GasUsed
h.Time = aura.Time
h.Extra = aura.Extra
h.MixDigest = common.Hash{}
h.Nonce = BlockNonce{}
h.Signatures = append(h.Signatures, aura.Signature1)
h.Signatures = append(h.Signatures, aura.Signature2)
return nil
}

// EncodeRLP serializes b into the Ethereum RLP block format.
func (header *Header) EncodeRLP(w io.Writer) error {
if false && header.Signatures != nil {
return rlp.Encode(w, []interface{}{
header.ParentHash,
header.UncleHash,
header.Coinbase,
header.Root,
header.TxHash,
header.ReceiptHash,
header.Bloom,
header.Difficulty,
header.Number,
header.GasLimit,
header.GasUsed,
header.Time,
header.Extra,
// Yes, this is butt-ugly
header.Signatures[0],
header.Signatures[1],
})
} else {
return rlp.Encode(w, []interface{}{
header.ParentHash,
header.UncleHash,
header.Coinbase,
header.Root,
header.TxHash,
header.ReceiptHash,
header.Bloom,
header.Difficulty,
header.Number,
header.GasLimit,
header.GasUsed,
header.Time,
header.Extra, // Yes, this will panic if extra is too short
header.MixDigest,
header.Nonce,
})
}
}

// Hash returns the block hash of the header, which is simply the keccak256 hash of its
// RLP encoding.
func (h *Header) Hash() common.Hash {
return rlpHash(h)
func (header *Header) Hash() (h common.Hash) {
//if header.Signatures == nil{
// return rlpHash(h)
//}
hw := sha3.NewKeccak256()

rlp.Encode(hw, []interface{}{
header.ParentHash,
header.UncleHash,
header.Coinbase,
header.Root,
header.TxHash,
header.ReceiptHash,
header.Bloom,
header.Difficulty,
header.Number,
header.GasLimit,
header.GasUsed,
header.Time,
header.Extra,
// Yes, this is butt-ugly
//header.Signatures[0],
//header.Signatures[1],
})
hw.Sum(h[:0])
return h

}

// Size returns the approximate memory used by all internal contents. It is used
Expand Down Expand Up @@ -288,9 +409,11 @@ func (b *Block) GasUsed() uint64 { return b.header.GasUsed }
func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
func (b *Block) Time() *big.Int { return new(big.Int).Set(b.header.Time) }

func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }
func (b *Block) Nonce() uint64 { return binary.BigEndian.Uint64(b.header.Nonce[:]) }
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
func (b *Block) MixDigest() common.Hash {
return common.Hash{}
}
func (b *Block) Nonce() uint64 { return 0 }
func (b *Block) Bloom() Bloom { return b.header.Bloom }
func (b *Block) Coinbase() common.Address { return b.header.Coinbase }
func (b *Block) Root() common.Hash { return b.header.Root }
Expand Down
75 changes: 35 additions & 40 deletions core/types/gen_header_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1743af1

Please sign in to comment.