mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00
[NOD-202] undo createDAGState if blockdag new fails (#318)
* [NOD-204] Add UTXOCommitment to GetBlockTemplateResult * [NOD-204] Add UTXOCommitment to GetBlockTemplateResult * [NOD-206] Avoid leaking blocks from previous miner when switching miners * [NOD-202] Undo createDAGState if blockdag.New fails * [NOD-202] Fix gofmt errors
This commit is contained in:
parent
33a4183bfa
commit
901bde1fd4
@ -1864,14 +1864,23 @@ func New(config *Config) (*BlockDAG, error) {
|
|||||||
// Initialize the chain state from the passed database. When the db
|
// Initialize the chain state from the passed database. When the db
|
||||||
// does not yet contain any DAG state, both it and the DAG state
|
// does not yet contain any DAG state, both it and the DAG state
|
||||||
// will be initialized to contain only the genesis block.
|
// will be initialized to contain only the genesis block.
|
||||||
if err := dag.initDAGState(); err != nil {
|
err := dag.initDAGState()
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
err := dag.removeDAGState()
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Couldn't remove the DAG State: %s", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Initialize and catch up all of the currently active optional indexes
|
// Initialize and catch up all of the currently active optional indexes
|
||||||
// as needed.
|
// as needed.
|
||||||
if config.IndexManager != nil {
|
if config.IndexManager != nil {
|
||||||
err := config.IndexManager.Init(dag.db, &dag, config.Interrupt)
|
err = config.IndexManager.Init(dag.db, &dag, config.Interrupt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1881,7 +1890,8 @@ func New(config *Config) (*BlockDAG, error) {
|
|||||||
|
|
||||||
if genesis == nil {
|
if genesis == nil {
|
||||||
genesisBlock := util.NewBlock(dag.dagParams.GenesisBlock)
|
genesisBlock := util.NewBlock(dag.dagParams.GenesisBlock)
|
||||||
isOrphan, err := dag.ProcessBlock(genesisBlock, BFNone)
|
var isOrphan bool
|
||||||
|
isOrphan, err = dag.ProcessBlock(genesisBlock, BFNone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1895,7 +1905,8 @@ func New(config *Config) (*BlockDAG, error) {
|
|||||||
dag.genesis = genesis
|
dag.genesis = genesis
|
||||||
|
|
||||||
// Initialize rule change threshold state caches.
|
// Initialize rule change threshold state caches.
|
||||||
if err := dag.initThresholdCaches(); err != nil {
|
err = dag.initThresholdCaches()
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,6 +344,49 @@ func (dag *BlockDAG) createDAGState() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dag *BlockDAG) removeDAGState() error {
|
||||||
|
err := dag.db.Update(func(dbTx database.Tx) error {
|
||||||
|
meta := dbTx.Metadata()
|
||||||
|
|
||||||
|
err := meta.DeleteBucket(blockIndexBucketName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = meta.DeleteBucket(utxoSetBucketName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = meta.DeleteBucket(utxoDiffsBucketName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = dbTx.Metadata().Delete(utxoSetVersionKeyName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = meta.DeleteBucket(subnetworksBucketName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = dbTx.Metadata().Delete(localSubnetworkKeyName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func dbPutLocalSubnetworkID(dbTx database.Tx, subnetworkID *subnetworkid.SubnetworkID) error {
|
func dbPutLocalSubnetworkID(dbTx database.Tx, subnetworkID *subnetworkid.SubnetworkID) error {
|
||||||
if subnetworkID == nil {
|
if subnetworkID == nil {
|
||||||
return dbTx.Metadata().Put(localSubnetworkKeyName, []byte{})
|
return dbTx.Metadata().Put(localSubnetworkKeyName, []byte{})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user