Added a friendly error message when genesis hash is not relevant to database (#1745)

Co-authored-by: Constantine Bitensky <constantinebitensky@gmail.com>
Co-authored-by: Svarog <feanorr@gmail.com>
This commit is contained in:
Constantine Bitensky 2021-06-13 11:36:47 +03:00 committed by GitHub
parent 2ae1b7853f
commit 70399dae2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,8 @@
package consensus
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/pkg/errors"
"io/ioutil"
"os"
"sync"
@ -418,6 +420,11 @@ func (f *factory) NewConsensus(config *Config, db infrastructuredatabase.Databas
}
if !genesisInfo.Exists {
if c.blockStore.Count(model.NewStagingArea()) > 0 {
return nil, errors.Errorf(
"expected genesis block %s is not found in the non-empty DAG \"%s\": wrong config or appdir?",
genesisHash, config.Params.Name)
}
_, err = c.ValidateAndInsertBlock(config.GenesisBlock)
if err != nil {
return nil, err