Skip to content

Commit f9917c8

Browse files
committed
core: improved chainDb using sequential keys
1 parent 5a458da commit f9917c8

24 files changed

Lines changed: 726 additions & 365 deletions

‎cmd/geth/chaincmd.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func dump(ctx *cli.Context) {
170170
for _, arg := range ctx.Args() {
171171
var block *types.Block
172172
if hashish(arg) {
173-
block = chain.GetBlock(common.HexToHash(arg))
173+
block = chain.GetBlockByHash(common.HexToHash(arg))
174174
} else {
175175
num, _ := strconv.Atoi(arg)
176176
block = chain.GetBlockByNumber(uint64(num))

‎cmd/utils/flags.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ func MustMakeChainConfig(ctx *cli.Context) *core.ChainConfig {
806806

807807
// MustMakeChainConfigFromDb reads the chain configuration from the given database.
808808
func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfig {
809-
genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0))
809+
genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0)
810810

811811
if genesis != nil {
812812
// Existing genesis block, use stored config if available.

‎core/bench_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
231231
hash = header.Hash()
232232
WriteHeader(db, header)
233233
WriteCanonicalHash(db, hash, n)
234-
WriteTd(db, hash, big.NewInt(int64(n+1)))
234+
WriteTd(db, hash, n, big.NewInt(int64(n+1)))
235235
if full || n == 0 {
236236
block := types.NewBlockWithHeader(header)
237-
WriteBody(db, hash, block.Body())
238-
WriteBlockReceipts(db, hash, nil)
237+
WriteBody(db, hash, n, block.Body())
238+
WriteBlockReceipts(db, hash, n, nil)
239239
}
240240
}
241241
}
@@ -287,8 +287,8 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
287287
header := chain.GetHeaderByNumber(n)
288288
if full {
289289
hash := header.Hash()
290-
GetBody(db, hash)
291-
GetBlockReceipts(db, hash)
290+
GetBody(db, hash, n)
291+
GetBlockReceipts(db, hash, n)
292292
}
293293
}
294294

‎core/block_validator.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (v *BlockValidator) ValidateBlock(block *types.Block) error {
7272
return &KnownBlockError{block.Number(), block.Hash()}
7373
}
7474
}
75-
parent := v.bc.GetBlock(block.ParentHash())
75+
parent := v.bc.GetBlock(block.ParentHash(), block.NumberU64()-1)
7676
if parent == nil {
7777
return ParentError(block.ParentHash())
7878
}

0 commit comments

Comments
 (0)