Skip to content

Commit 1743af1

Browse files
holimanpriom
authored andcommitted
Fixes (#27)
* aura: genesis + init-script * aura genesis * core, params: wip on aura, still not working
1 parent e177f52 commit 1743af1

File tree

6 files changed

+209
-74
lines changed

6 files changed

+209
-74
lines changed

aura.genesis

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"authorities":[
1313
"0x0082a7bf6aaadab094061747872243059c3c6a07",
1414
"0x00faa37564140c1a5e96095f05466b9f73441e44"],
15-
"difficulty" : 131072
15+
"difficulty" : 131072,
16+
"signatures": ["gA==","uEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACsHcD/7g=="]
1617
}
1718
},
1819
"nonce": "0x0",

consensus/aura/aura.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func (a *Aura) verifyHeader(chain consensus.ChainReader, header *types.Header, p
286286
return errInvalidExtraData
287287
}
288288
// Ensure that the mix digest is zero as we don't have fork protection currently
289-
if header.MixDigest != (common.Hash{}) {
289+
if header.MixDig() != (common.Hash{}) {
290290
return errInvalidMixDigest
291291
}
292292
// Ensure that the block doesn't contain any uncles which are meaningless in PoA

core/genesis.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
234234
}
235235
}
236236
root := statedb.IntermediateRoot(false)
237+
238+
237239
head := &types.Header{
238240
Number: new(big.Int).SetUint64(g.Number),
239241
Nonce: types.EncodeNonce(g.Nonce),
@@ -247,12 +249,21 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
247249
Coinbase: g.Coinbase,
248250
Root: root,
249251
}
252+
253+
if g.Config.Aura != nil {
254+
for _, signature := range g.Config.Aura.Signatures {
255+
head.Signatures = append(head.Signatures, signature)
256+
}
257+
}
250258
if g.GasLimit == 0 {
251259
head.GasLimit = params.GenesisGasLimit
252260
}
253261
if g.Difficulty == nil {
254262
head.Difficulty = params.GenesisDifficulty
255263
}
264+
data,_ := rlp.EncodeToBytes(head)
265+
fmt.Printf("Genesis header rlp %v\n", common.Bytes2Hex(data))
266+
256267
statedb.Commit(false)
257268
statedb.Database().TrieDB().Commit(root, true)
258269

@@ -332,6 +343,7 @@ func DefaultRinkebyGenesisBlock() *Genesis {
332343
Alloc: decodePrealloc(rinkebyAllocData),
333344
}
334345
}
346+
335347
//Need alloc data
336348
// DefaultGoerliGenesisBlock returns the Goerli network genesis block.
337349
func DefaultGoerliGenesisBlock() *Genesis {

core/types/block.go

Lines changed: 143 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package types
1919

2020
import (
2121
"encoding/binary"
22+
"github.com/ethereum/go-ethereum/params"
2223
"io"
2324
"math/big"
2425
"sort"
@@ -65,24 +66,46 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
6566
}
6667

6768
//go:generate gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
69+
type AuraHeader struct {
70+
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
71+
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
72+
Coinbase common.Address `json:"miner" gencodec:"required"`
73+
Root common.Hash `json:"stateRoot" gencodec:"required"`
74+
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
75+
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
76+
Bloom Bloom `json:"logsBloom" gencodec:"required"`
77+
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
78+
Number *big.Int `json:"number" gencodec:"required"`
79+
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
80+
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
81+
Time *big.Int `json:"timestamp" gencodec:"required"`
82+
Extra []byte `json:"extraData" gencodec:"required"`
83+
Signature1 []byte `json:"signature1,omitempty"`
84+
Signature2 []byte `json:"signature2,omitempty"`
85+
}
6886

6987
// Header represents a block header in the Ethereum blockchain.
7088
type Header struct {
71-
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
72-
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
73-
Coinbase common.Address `json:"miner" gencodec:"required"`
74-
Root common.Hash `json:"stateRoot" gencodec:"required"`
75-
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
76-
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
77-
Bloom Bloom `json:"logsBloom" gencodec:"required"`
78-
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
79-
Number *big.Int `json:"number" gencodec:"required"`
80-
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
81-
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
82-
Time *big.Int `json:"timestamp" gencodec:"required"`
83-
Extra []byte `json:"extraData" gencodec:"required"`
84-
MixDigest common.Hash `json:"mixHash" gencodec:"required"`
85-
Nonce BlockNonce `json:"nonce" gencodec:"required"`
89+
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
90+
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
91+
Coinbase common.Address `json:"miner" gencodec:"required"`
92+
Root common.Hash `json:"stateRoot" gencodec:"required"`
93+
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
94+
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
95+
Bloom Bloom `json:"logsBloom" gencodec:"required"`
96+
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
97+
Number *big.Int `json:"number" gencodec:"required"`
98+
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
99+
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
100+
Time *big.Int `json:"timestamp" gencodec:"required"`
101+
Extra []byte `json:"extraData" gencodec:"required"`
102+
MixDigest common.Hash `json:"mixHash" gencodec:"required"`
103+
Nonce BlockNonce `json:"nonce" gencodec:"required"`
104+
Signatures params.Signatures `json:"signature,omitempty"`
105+
}
106+
107+
func (h *Header) MixDig() common.Hash {
108+
return common.Hash{}
86109
}
87110

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

122+
// DecodeRLP decodes the Ethereum
123+
func (h *Header) DecodeRLP(s *rlp.Stream) error {
124+
125+
var aura AuraHeader
126+
127+
// Try decoding as aura header first
128+
if err := s.Decode(&aura); err != nil {
129+
return err
130+
//return s.Decode(h)
131+
}
132+
//Aura decoded fine, now convert to header
133+
h.ParentHash = aura.ParentHash
134+
h.UncleHash = aura.UncleHash
135+
h.Coinbase = aura.Coinbase
136+
h.Root = aura.Root
137+
h.TxHash = aura.TxHash
138+
h.ReceiptHash = aura.ReceiptHash
139+
h.Bloom = aura.Bloom
140+
h.Difficulty = aura.Difficulty
141+
h.Number = aura.Number
142+
h.GasLimit = aura.GasLimit
143+
h.GasUsed = aura.GasUsed
144+
h.Time = aura.Time
145+
h.Extra = aura.Extra
146+
h.MixDigest = common.Hash{}
147+
h.Nonce = BlockNonce{}
148+
h.Signatures = append(h.Signatures, aura.Signature1)
149+
h.Signatures = append(h.Signatures, aura.Signature2)
150+
return nil
151+
}
152+
153+
// EncodeRLP serializes b into the Ethereum RLP block format.
154+
func (header *Header) EncodeRLP(w io.Writer) error {
155+
if false && header.Signatures != nil {
156+
return rlp.Encode(w, []interface{}{
157+
header.ParentHash,
158+
header.UncleHash,
159+
header.Coinbase,
160+
header.Root,
161+
header.TxHash,
162+
header.ReceiptHash,
163+
header.Bloom,
164+
header.Difficulty,
165+
header.Number,
166+
header.GasLimit,
167+
header.GasUsed,
168+
header.Time,
169+
header.Extra,
170+
// Yes, this is butt-ugly
171+
header.Signatures[0],
172+
header.Signatures[1],
173+
})
174+
} else {
175+
return rlp.Encode(w, []interface{}{
176+
header.ParentHash,
177+
header.UncleHash,
178+
header.Coinbase,
179+
header.Root,
180+
header.TxHash,
181+
header.ReceiptHash,
182+
header.Bloom,
183+
header.Difficulty,
184+
header.Number,
185+
header.GasLimit,
186+
header.GasUsed,
187+
header.Time,
188+
header.Extra, // Yes, this will panic if extra is too short
189+
header.MixDigest,
190+
header.Nonce,
191+
})
192+
}
193+
}
194+
99195
// Hash returns the block hash of the header, which is simply the keccak256 hash of its
100196
// RLP encoding.
101-
func (h *Header) Hash() common.Hash {
102-
return rlpHash(h)
197+
func (header *Header) Hash() (h common.Hash) {
198+
//if header.Signatures == nil{
199+
// return rlpHash(h)
200+
//}
201+
hw := sha3.NewKeccak256()
202+
203+
rlp.Encode(hw, []interface{}{
204+
header.ParentHash,
205+
header.UncleHash,
206+
header.Coinbase,
207+
header.Root,
208+
header.TxHash,
209+
header.ReceiptHash,
210+
header.Bloom,
211+
header.Difficulty,
212+
header.Number,
213+
header.GasLimit,
214+
header.GasUsed,
215+
header.Time,
216+
header.Extra,
217+
// Yes, this is butt-ugly
218+
//header.Signatures[0],
219+
//header.Signatures[1],
220+
})
221+
hw.Sum(h[:0])
222+
return h
223+
103224
}
104225

105226
// 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 }
288409
func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
289410
func (b *Block) Time() *big.Int { return new(big.Int).Set(b.header.Time) }
290411

291-
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
292-
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }
293-
func (b *Block) Nonce() uint64 { return binary.BigEndian.Uint64(b.header.Nonce[:]) }
412+
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
413+
func (b *Block) MixDigest() common.Hash {
414+
return common.Hash{}
415+
}
416+
func (b *Block) Nonce() uint64 { return 0 }
294417
func (b *Block) Bloom() Bloom { return b.header.Bloom }
295418
func (b *Block) Coinbase() common.Address { return b.header.Coinbase }
296419
func (b *Block) Root() common.Hash { return b.header.Root }

core/types/gen_header_json.go

Lines changed: 35 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)