diff --git a/aura.genesis b/aura.genesis index fc3d6adb1ca6..cdddbd7f2ac7 100644 --- a/aura.genesis +++ b/aura.genesis @@ -12,7 +12,8 @@ "authorities":[ "0x0082a7bf6aaadab094061747872243059c3c6a07", "0x00faa37564140c1a5e96095f05466b9f73441e44"], - "difficulty" : 131072 + "difficulty" : 131072, + "signatures": ["gA==","uEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACsHcD/7g=="] } }, "nonce": "0x0", diff --git a/consensus/aura/aura.go b/consensus/aura/aura.go index 3a7f0e8a9792..3844fd0ccd0a 100644 --- a/consensus/aura/aura.go +++ b/consensus/aura/aura.go @@ -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 diff --git a/core/genesis.go b/core/genesis.go index 46be2f64c237..c31c4b14fafd 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -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), @@ -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) @@ -332,6 +343,7 @@ func DefaultRinkebyGenesisBlock() *Genesis { Alloc: decodePrealloc(rinkebyAllocData), } } + //Need alloc data // DefaultGoerliGenesisBlock returns the Goerli network genesis block. func DefaultGoerliGenesisBlock() *Genesis { diff --git a/core/types/block.go b/core/types/block.go index 8a21bba1e783..1f3b43563548 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -19,6 +19,7 @@ package types import ( "encoding/binary" + "github.com/ethereum/go-ethereum/params" "io" "math/big" "sort" @@ -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 @@ -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 @@ -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 } diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index 1b92cd9cf44f..ff22a18af7e1 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -9,28 +9,29 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/params" ) var _ = (*headerMarshaling)(nil) +// MarshalJSON marshals as JSON. func (h Header) MarshalJSON() ([]byte, error) { 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 *hexutil.Big `json:"difficulty" gencodec:"required"` - Number *hexutil.Big `json:"number" gencodec:"required"` - GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"` - GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"` - Time *hexutil.Big `json:"timestamp" gencodec:"required"` - Extra hexutil.Bytes `json:"extraData" gencodec:"required"` - MixDigest common.Hash `json:"mixHash" gencodec:"required"` - Nonce BlockNonce `json:"nonce" gencodec:"required"` - Hash common.Hash `json:"hash"` + 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 *hexutil.Big `json:"difficulty" gencodec:"required"` + Number *hexutil.Big `json:"number" gencodec:"required"` + GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"` + GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"` + Time *hexutil.Big `json:"timestamp" gencodec:"required"` + Extra hexutil.Bytes `json:"extraData" gencodec:"required"` + Signatures params.Signatures `json:"signature,omitempty"` + Hash common.Hash `json:"hash"` } var enc Header enc.ParentHash = h.ParentHash @@ -46,29 +47,28 @@ func (h Header) MarshalJSON() ([]byte, error) { enc.GasUsed = hexutil.Uint64(h.GasUsed) enc.Time = (*hexutil.Big)(h.Time) enc.Extra = h.Extra - enc.MixDigest = h.MixDigest - enc.Nonce = h.Nonce + enc.Signatures = h.Signatures enc.Hash = h.Hash() return json.Marshal(&enc) } +// UnmarshalJSON unmarshals from JSON. func (h *Header) UnmarshalJSON(input []byte) error { 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 *hexutil.Big `json:"difficulty" gencodec:"required"` - Number *hexutil.Big `json:"number" gencodec:"required"` - GasLimit *hexutil.Uint64 `json:"gasLimit" gencodec:"required"` - GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"` - Time *hexutil.Big `json:"timestamp" gencodec:"required"` - Extra *hexutil.Bytes `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 *hexutil.Big `json:"difficulty" gencodec:"required"` + Number *hexutil.Big `json:"number" gencodec:"required"` + GasLimit *hexutil.Uint64 `json:"gasLimit" gencodec:"required"` + GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"` + Time *hexutil.Big `json:"timestamp" gencodec:"required"` + Extra *hexutil.Bytes `json:"extraData" gencodec:"required"` + Signatures *params.Signatures `json:"signature,omitempty"` } var dec Header if err := json.Unmarshal(input, &dec); err != nil { @@ -126,13 +126,8 @@ func (h *Header) UnmarshalJSON(input []byte) error { return errors.New("missing required field 'extraData' for Header") } h.Extra = *dec.Extra - if dec.MixDigest == nil { - return errors.New("missing required field 'mixHash' for Header") + if dec.Signatures != nil { + h.Signatures = *dec.Signatures } - h.MixDigest = *dec.MixDigest - if dec.Nonce == nil { - return errors.New("missing required field 'nonce' for Header") - } - h.Nonce = *dec.Nonce return nil } diff --git a/params/config.go b/params/config.go index 8cac41a16bc5..03dc63b3e54e 100644 --- a/params/config.go +++ b/params/config.go @@ -18,8 +18,8 @@ package params import ( "fmt" - "math/big" "github.com/ethereum/go-ethereum/common" + "math/big" ) // Genesis hashes to enforce below configs on. @@ -81,12 +81,12 @@ var ( // GoerliChainConfig contains the chain parameters to run a node on the Goerli test network. GoerliChainConfig = &ChainConfig{ - ChainID: big.NewInt(6382), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: false, - // EIP150Block: big.NewInt(0), - // EIP150Hash: common.HexToHash("0X0000000000000000000000000000000000000000000000000000000000000000"), + ChainID: big.NewInt(6382), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: false, + // EIP150Block: big.NewInt(0), + // EIP150Hash: common.HexToHash("0X0000000000000000000000000000000000000000000000000000000000000000"), EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), ByzantiumBlock: big.NewInt(0), @@ -96,7 +96,7 @@ var ( common.HexToAddress("0x0082a7bf6aaadab094061747872243059c3c6a07"), common.HexToAddress("0x00faa37564140c1a5e96095f05466b9f73441e44"), }, - Difficulty: big.NewInt(131072), + Difficulty: big.NewInt(131072), }, } @@ -146,7 +146,7 @@ type ChainConfig struct { // Various consensus engines Ethash *EthashConfig `json:"ethash,omitempty"` Clique *CliqueConfig `json:"clique,omitempty"` - Aura *AuraConfig `json:"aura,omitempty"` + Aura *AuraConfig `json:"aura,omitempty"` } // EthashConfig is the consensus engine configs for proof-of-work based sealing. @@ -163,12 +163,16 @@ type CliqueConfig struct { Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint } +type Signature []byte +type Signatures []Signature + // AuraConfig is the consensus engine configs for proof-of-authority based sealing. type AuraConfig struct { - Period uint64 `json:"period"` // Number of seconds between blocks to enforce - Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint + Period uint64 `json:"period"` // Number of seconds between blocks to enforce + Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint Authorities []common.Address `json:"authorities"` // list of addresses of authorities - Difficulty *big.Int `json:"difficulty"` // Constant block difficulty + Difficulty *big.Int `json:"difficulty"` // Constant block difficulty + Signatures Signatures `json:"signatures"` } // String implements the stringer interface, returning the consensus engine details.