diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/state_processor.go | 3 | ||||
-rw-r--r-- | core/types/block.go | 73 |
2 files changed, 70 insertions, 6 deletions
diff --git a/core/state_processor.go b/core/state_processor.go index 6cc646a..ab8759a 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -75,6 +75,9 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg receipts = append(receipts, receipt) allLogs = append(allLogs, receipt.Logs...) } + if err := p.engine.ExtraStateChange(block, statedb); err != nil { + return nil, nil, 0, err + } // Finalize the block, applying any consensus engine specific extras (e.g. block rewards) p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles()) diff --git a/core/types/block.go b/core/types/block.go index 2fdc904..6fa710a 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -18,6 +18,7 @@ package types import ( + "bytes" "encoding/binary" "fmt" "io" @@ -149,6 +150,8 @@ type Block struct { header *Header uncles []*Header transactions Transactions + version uint32 + extdata []byte // caches hash atomic.Value @@ -184,6 +187,14 @@ type extblock struct { Uncles []*Header } +type myextblock struct { + Header *Header + Txs []*Transaction + Uncles []*Header + Version uint32 + ExtData []byte `rlp:"nil"` +} + // [deprecated by eth/63] // "storage" block encoding. used for database. type storageblock struct { @@ -258,18 +269,47 @@ func CopyHeader(h *Header) *Header { // DecodeRLP decodes the Ethereum func (b *Block) DecodeRLP(s *rlp.Stream) error { + bs, _ := s.Raw() + copied := make([]byte, len(bs)) + copy(copied, bs) + ss := rlp.NewStream(bytes.NewReader(bs), 0) + var eb extblock - _, size, _ := s.Kind() - if err := s.Decode(&eb); err != nil { - return err + _, size, _ := ss.Kind() + if err := ss.Decode(&eb); err != nil { + var meb myextblock + ss = rlp.NewStream(bytes.NewReader(copied), 0) + if err := ss.Decode(&meb); err != nil { + return err + } + b.header, b.uncles, b.transactions = meb.Header, meb.Uncles, meb.Txs + b.extdata = meb.ExtData + } else { + b.header, b.uncles, b.transactions = eb.Header, eb.Uncles, eb.Txs + b.extdata = nil } - b.header, b.uncles, b.transactions = eb.Header, eb.Uncles, eb.Txs b.size.Store(common.StorageSize(rlp.ListSize(size))) return nil } -// EncodeRLP serializes b into the Ethereum RLP block format. -func (b *Block) EncodeRLP(w io.Writer) error { +func (b *Block) SetExtraData(data []byte) { + b.extdata = data +} + +func (b *Block) ExtraData() []byte { + return b.extdata +} + +func (b *Block) SetVersion(ver uint32) { + b.version = ver +} + +func (b *Block) Version() uint32 { + return b.version +} + +// EncodeRLPEth serializes b into the Ethereum RLP block format. +func (b *Block) EncodeRLPEth(w io.Writer) error { return rlp.Encode(w, extblock{ Header: b.header, Txs: b.transactions, @@ -277,6 +317,27 @@ func (b *Block) EncodeRLP(w io.Writer) error { }) } +func (b *Block) EncodeRLPTest(w io.Writer, ver uint32) error { + return rlp.Encode(w, myextblock{ + Header: b.header, + Txs: b.transactions, + Uncles: b.uncles, + Version: ver, + ExtData: b.extdata, + }) +} + +// EncodeRLP serializes b into an extended format. +func (b *Block) EncodeRLP(w io.Writer) error { + return rlp.Encode(w, myextblock{ + Header: b.header, + Txs: b.transactions, + Uncles: b.uncles, + Version: b.version, + ExtData: b.extdata, + }) +} + // [deprecated by eth/63] func (b *StorageBlock) DecodeRLP(s *rlp.Stream) error { var sb storageblock |