Skip to content

Commit 24cdac4

Browse files
committed
core, core/types, eth: add and use Block.Body
This fixes a few uses of unkeyed Body literals which go vet was complaining about.
1 parent fdc5a7d commit 24cdac4

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

core/blockchain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ func (self *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain
678678
}
679679
}
680680
// Write all the data out into the database
681-
if err := WriteBody(self.chainDb, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
681+
if err := WriteBody(self.chainDb, block.Hash(), block.Body()); err != nil {
682682
errs[index] = fmt.Errorf("failed to write block body: %v", err)
683683
atomic.AddInt32(&failed, 1)
684684
glog.Fatal(errs[index])

core/database_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func WriteTd(db ethdb.Database, hash common.Hash, td *big.Int) error {
318318
// WriteBlock serializes a block into the database, header and body separately.
319319
func WriteBlock(db ethdb.Database, block *types.Block) error {
320320
// Store the body first to retain database consistency
321-
if err := WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
321+
if err := WriteBody(db, block.Hash(), block.Body()); err != nil {
322322
return err
323323
}
324324
// Store the header too, signaling full block ownership

core/database_util_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func TestBlockStorage(t *testing.T) {
196196
if entry := GetBody(db, block.Hash()); entry == nil {
197197
t.Fatalf("Stored body not found")
198198
} else if types.DeriveSha(types.Transactions(entry.Transactions)) != types.DeriveSha(block.Transactions()) || types.CalcUncleHash(entry.Uncles) != types.CalcUncleHash(block.Uncles()) {
199-
t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, &types.Body{block.Transactions(), block.Uncles()})
199+
t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, block.Body())
200200
}
201201
// Delete the block and verify the execution
202202
DeleteBlock(db, block.Hash())
@@ -230,7 +230,7 @@ func TestPartialBlockStorage(t *testing.T) {
230230
DeleteHeader(db, block.Hash())
231231

232232
// Store a body and check that it's not recognized as a block
233-
if err := WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
233+
if err := WriteBody(db, block.Hash(), block.Body()); err != nil {
234234
t.Fatalf("Failed to write body into database: %v", err)
235235
}
236236
if entry := GetBlock(db, block.Hash()); entry != nil {
@@ -242,7 +242,7 @@ func TestPartialBlockStorage(t *testing.T) {
242242
if err := WriteHeader(db, block.Header()); err != nil {
243243
t.Fatalf("Failed to write header into database: %v", err)
244244
}
245-
if err := WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
245+
if err := WriteBody(db, block.Hash(), block.Body()); err != nil {
246246
t.Fatalf("Failed to write body into database: %v", err)
247247
}
248248
if entry := GetBlock(db, block.Hash()); entry == nil {

core/types/block.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Ext
330330

331331
func (b *Block) Header() *Header { return CopyHeader(b.header) }
332332

333+
// Body returns the non-header content of the block.
334+
func (b *Block) Body() *Body { return &Body{b.transactions, b.uncles} }
335+
333336
func (b *Block) HashNoNonce() common.Hash {
334337
return b.header.HashNoNonce()
335338
}

eth/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ func upgradeChainDatabase(db ethdb.Database) error {
557557
if err := core.WriteTd(db, block.Hash(), block.DeprecatedTd()); err != nil {
558558
return err
559559
}
560-
if err := core.WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
560+
if err := core.WriteBody(db, block.Hash(), block.Body()); err != nil {
561561
return err
562562
}
563563
if err := core.WriteHeader(db, block.Header()); err != nil {
@@ -573,7 +573,7 @@ func upgradeChainDatabase(db ethdb.Database) error {
573573
if err := core.WriteTd(db, current.Hash(), current.DeprecatedTd()); err != nil {
574574
return err
575575
}
576-
if err := core.WriteBody(db, current.Hash(), &types.Body{current.Transactions(), current.Uncles()}); err != nil {
576+
if err := core.WriteBody(db, current.Hash(), current.Body()); err != nil {
577577
return err
578578
}
579579
if err := core.WriteHeader(db, current.Header()); err != nil {

0 commit comments

Comments
 (0)