diff --git a/blockbook.go b/blockbook.go index d4288098..cca19881 100644 --- a/blockbook.go +++ b/blockbook.go @@ -156,7 +156,7 @@ func main() { } defer index.Close() - common.IS, err = index.LoadInternalState() + common.IS, err = index.LoadInternalState(*coin) if err != nil { glog.Fatal("internalState: ", err) } diff --git a/common/internalstate.go b/common/internalstate.go index 5827d8e6..8881d854 100644 --- a/common/internalstate.go +++ b/common/internalstate.go @@ -26,6 +26,8 @@ type InternalStateColumn struct { type InternalState struct { mux sync.Mutex + Coin string `json:"coin"` + DbState uint32 `json:"dbState"` LastStore time.Time `json:"lastStore"` diff --git a/db/rocksdb.go b/db/rocksdb.go index 97e8fb84..ab1b86e2 100644 --- a/db/rocksdb.go +++ b/db/rocksdb.go @@ -875,7 +875,7 @@ func (d *RocksDB) DeleteTx(txid string) error { const internalStateKey = "internalState" // LoadInternalState loads from db internal state or initializes a new one if not yet stored -func (d *RocksDB) LoadInternalState() (*common.InternalState, error) { +func (d *RocksDB) LoadInternalState(rpcCoin string) (*common.InternalState, error) { val, err := d.db.GetCF(d.ro, d.cfh[cfDefault], []byte(internalStateKey)) if err != nil { return nil, err @@ -884,12 +884,19 @@ func (d *RocksDB) LoadInternalState() (*common.InternalState, error) { data := val.Data() var is *common.InternalState if len(data) == 0 { - is = &common.InternalState{} + is = &common.InternalState{Coin: rpcCoin} } else { is, err = common.UnpackInternalState(data) if err != nil { return nil, err } + // verify that the rpc coin matches DB coin + // running it mismatched would corrupt the database + if is.Coin == "" { + is.Coin = rpcCoin + } else if is.Coin != rpcCoin { + return nil, errors.Errorf("Coins do not match. DB coin %v, RPC coin %v", is.Coin, rpcCoin) + } } // make sure that column stats match the columns sc := is.DbColumns