aboutsummaryrefslogtreecommitdiffstats
path: root/eth/backend.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-09-08 01:43:01 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-09-11 22:42:25 +0800
commitcdc2662c4098d68a7b450b9b9ff2688acbffcee4 (patch)
tree2dfb3b7365895203132bd6d1aa650b5a239b01eb /eth/backend.go
parent2b339cbbd8bb475d2195d54a71dcced700003430 (diff)
downloaddexon-cdc2662c4098d68a7b450b9b9ff2688acbffcee4.tar.gz
dexon-cdc2662c4098d68a7b450b9b9ff2688acbffcee4.tar.zst
dexon-cdc2662c4098d68a7b450b9b9ff2688acbffcee4.zip
core: split out TD from database and all internals
Diffstat (limited to 'eth/backend.go')
-rw-r--r--eth/backend.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/eth/backend.go b/eth/backend.go
index 59f2ab01a..deb6d3d0f 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -316,9 +316,13 @@ func New(config *Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
- case config.GenesisBlock != nil: // This is for testing only.
+ }
+ // This is for testing only.
+ if config.GenesisBlock != nil {
+ core.WriteTd(chainDb, config.GenesisBlock.Hash(), config.GenesisBlock.Difficulty())
core.WriteBlock(chainDb, config.GenesisBlock)
- core.WriteHead(chainDb, config.GenesisBlock)
+ core.WriteCanonicalHash(chainDb, config.GenesisBlock.Hash(), config.GenesisBlock.NumberU64())
+ core.WriteHeadBlockHash(chainDb, config.GenesisBlock.Hash())
}
if !config.SkipBcVersionCheck {
@@ -752,7 +756,10 @@ func upgradeChainDatabase(db common.Database) error {
// Load the block, split and serialize (order!)
block := core.GetBlockByHashOld(db, common.BytesToHash(bytes.TrimPrefix(it.Key(), blockPrefix)))
- if err := core.WriteBody(db, block); err != nil {
+ 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 {
return err
}
if err := core.WriteHeader(db, block.Header()); err != nil {
@@ -765,7 +772,10 @@ func upgradeChainDatabase(db common.Database) error {
// Lastly, upgrade the head block, disabling the upgrade mechanism
current := core.GetBlockByHashOld(db, head)
- if err := core.WriteBody(db, current); err != nil {
+ 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 {
return err
}
if err := core.WriteHeader(db, current.Header()); err != nil {