aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go4
-rw-r--r--core/genesis.go2
-rw-r--r--core/rawdb/accessors_chain.go2
-rw-r--r--core/types/block.go14
4 files changed, 17 insertions, 5 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 64c2451..6e316c7 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -732,6 +732,8 @@ func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block {
// GetBlockByHash retrieves a block from the database by hash, caching it if found.
func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block {
+ bc.chainmu.Lock()
+ defer bc.chainmu.Unlock()
number := bc.hc.GetBlockNumber(hash)
if number == nil {
return nil
@@ -742,6 +744,8 @@ func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block {
// GetBlockByNumber retrieves a block from the database by number, caching it
// (associated with its hash) if found.
func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block {
+ bc.chainmu.Lock()
+ defer bc.chainmu.Unlock()
hash := rawdb.ReadCanonicalHash(bc.db, number)
if hash == (common.Hash{}) {
return nil
diff --git a/core/genesis.go b/core/genesis.go
index ef490bf..7d21d00 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -294,7 +294,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
statedb.Commit(false)
statedb.Database().TrieDB().Commit(root, true)
- return types.NewBlock(head, nil, nil, nil)
+ return types.NewBlock(head, nil, nil, nil, nil)
}
// Commit writes the block and state of a genesis specification to the database.
diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go
index 7620eac..fdfd6ec 100644
--- a/core/rawdb/accessors_chain.go
+++ b/core/rawdb/accessors_chain.go
@@ -475,7 +475,7 @@ func ReadBlock(db ethdb.Reader, hash common.Hash, number uint64) *types.Block {
if body == nil {
return nil
}
- return types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles)
+ return types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles, body.Version, body.ExtData)
}
// WriteBlock serializes a block into the database, header and body separately.
diff --git a/core/types/block.go b/core/types/block.go
index b3dbcd3..4096d86 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -144,6 +144,8 @@ func rlpHash(x interface{}) (h common.Hash) {
type Body struct {
Transactions []*Transaction
Uncles []*Header
+ Version uint32
+ ExtData []byte `rlp:"nil"`
}
// Block represents an entire block in the Ethereum blockchain.
@@ -212,7 +214,7 @@ type storageblock struct {
// The values of TxHash, UncleHash, ReceiptHash and Bloom in header
// are ignored and set to values derived from the given txs, uncles
// and receipts.
-func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt) *Block {
+func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, extdata []byte) *Block {
b := &Block{header: CopyHeader(header), td: new(big.Int)}
// TODO: panic if len(txs) != len(receipts)
@@ -241,6 +243,9 @@ func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*
}
}
+ b.extdata = make([]byte, len(extdata))
+ copy(b.extdata, extdata)
+
return b
}
@@ -387,7 +392,7 @@ func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Ext
func (b *Block) Header() *Header { return CopyHeader(b.header) }
// Body returns the non-header content of the block.
-func (b *Block) Body() *Body { return &Body{b.transactions, b.uncles} }
+func (b *Block) Body() *Body { return &Body{b.transactions, b.uncles, b.version, b.extdata} }
// Size returns the true RLP encoded storage size of the block, either by encoding
// and returning it, or returning a previsouly cached value.
@@ -434,13 +439,16 @@ func (b *Block) WithSeal(header *Header) *Block {
}
// WithBody returns a new block with the given transaction and uncle contents.
-func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block {
+func (b *Block) WithBody(transactions []*Transaction, uncles []*Header, version uint32, extdata []byte) *Block {
block := &Block{
header: CopyHeader(b.header),
transactions: make([]*Transaction, len(transactions)),
uncles: make([]*Header, len(uncles)),
+ extdata: make([]byte, len(extdata)),
+ version: version,
}
copy(block.transactions, transactions)
+ copy(block.extdata, extdata)
for i := range uncles {
block.uncles[i] = CopyHeader(uncles[i])
}