aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-04-15 16:57:37 +0800
committerFelix Lange <fjl@twurst.com>2016-04-15 16:57:37 +0800
commit24cdac41f34b37145c89572712db0854dd411110 (patch)
tree54c96106a142408bbe0408c7905fed25c22f1bff
parentfdc5a7dc1a1764c63190a649f70296cbdbc0abe1 (diff)
downloaddexon-24cdac41f34b37145c89572712db0854dd411110.tar.gz
dexon-24cdac41f34b37145c89572712db0854dd411110.tar.zst
dexon-24cdac41f34b37145c89572712db0854dd411110.zip
core, core/types, eth: add and use Block.Body
This fixes a few uses of unkeyed Body literals which go vet was complaining about.
-rw-r--r--core/blockchain.go2
-rw-r--r--core/database_util.go2
-rw-r--r--core/database_util_test.go6
-rw-r--r--core/types/block.go3
-rw-r--r--eth/backend.go4
5 files changed, 10 insertions, 7 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 177a3bbce..e740eb861 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -678,7 +678,7 @@ func (self *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain
}
}
// Write all the data out into the database
- if err := WriteBody(self.chainDb, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
+ if err := WriteBody(self.chainDb, block.Hash(), block.Body()); err != nil {
errs[index] = fmt.Errorf("failed to write block body: %v", err)
atomic.AddInt32(&failed, 1)
glog.Fatal(errs[index])
diff --git a/core/database_util.go b/core/database_util.go
index e1e8136d1..3ba80062c 100644
--- a/core/database_util.go
+++ b/core/database_util.go
@@ -318,7 +318,7 @@ func WriteTd(db ethdb.Database, hash common.Hash, td *big.Int) error {
// WriteBlock serializes a block into the database, header and body separately.
func WriteBlock(db ethdb.Database, block *types.Block) error {
// Store the body first to retain database consistency
- if err := WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
+ if err := WriteBody(db, block.Hash(), block.Body()); err != nil {
return err
}
// Store the header too, signaling full block ownership
diff --git a/core/database_util_test.go b/core/database_util_test.go
index ce1ffea8a..9ef787624 100644
--- a/core/database_util_test.go
+++ b/core/database_util_test.go
@@ -196,7 +196,7 @@ func TestBlockStorage(t *testing.T) {
if entry := GetBody(db, block.Hash()); entry == nil {
t.Fatalf("Stored body not found")
} else if types.DeriveSha(types.Transactions(entry.Transactions)) != types.DeriveSha(block.Transactions()) || types.CalcUncleHash(entry.Uncles) != types.CalcUncleHash(block.Uncles()) {
- t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, &types.Body{block.Transactions(), block.Uncles()})
+ t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, block.Body())
}
// Delete the block and verify the execution
DeleteBlock(db, block.Hash())
@@ -230,7 +230,7 @@ func TestPartialBlockStorage(t *testing.T) {
DeleteHeader(db, block.Hash())
// Store a body and check that it's not recognized as a block
- if err := WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
+ if err := WriteBody(db, block.Hash(), block.Body()); err != nil {
t.Fatalf("Failed to write body into database: %v", err)
}
if entry := GetBlock(db, block.Hash()); entry != nil {
@@ -242,7 +242,7 @@ func TestPartialBlockStorage(t *testing.T) {
if err := WriteHeader(db, block.Header()); err != nil {
t.Fatalf("Failed to write header into database: %v", err)
}
- if err := WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
+ if err := WriteBody(db, block.Hash(), block.Body()); err != nil {
t.Fatalf("Failed to write body into database: %v", err)
}
if entry := GetBlock(db, block.Hash()); entry == nil {
diff --git a/core/types/block.go b/core/types/block.go
index 5e6a9019d..387a063ae 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -330,6 +330,9 @@ 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) HashNoNonce() common.Hash {
return b.header.HashNoNonce()
}
diff --git a/eth/backend.go b/eth/backend.go
index ea12e4215..76cf8783b 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -557,7 +557,7 @@ func upgradeChainDatabase(db ethdb.Database) error {
if err := core.WriteTd(db, block.Hash(), block.DeprecatedTd()); err != nil {
return err
}
- if err := core.WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
+ if err := core.WriteBody(db, block.Hash(), block.Body()); err != nil {
return err
}
if err := core.WriteHeader(db, block.Header()); err != nil {
@@ -573,7 +573,7 @@ func upgradeChainDatabase(db ethdb.Database) error {
if err := core.WriteTd(db, current.Hash(), current.DeprecatedTd()); err != nil {
return err
}
- if err := core.WriteBody(db, current.Hash(), &types.Body{current.Transactions(), current.Uncles()}); err != nil {
+ if err := core.WriteBody(db, current.Hash(), current.Body()); err != nil {
return err
}
if err := core.WriteHeader(db, current.Header()); err != nil {