Store coin in internal state and verify that rpc coin matches db coin
parent
96f25ce11a
commit
c03b3d8a1a
|
@ -156,7 +156,7 @@ func main() {
|
||||||
}
|
}
|
||||||
defer index.Close()
|
defer index.Close()
|
||||||
|
|
||||||
common.IS, err = index.LoadInternalState()
|
common.IS, err = index.LoadInternalState(*coin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal("internalState: ", err)
|
glog.Fatal("internalState: ", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ type InternalStateColumn struct {
|
||||||
type InternalState struct {
|
type InternalState struct {
|
||||||
mux sync.Mutex
|
mux sync.Mutex
|
||||||
|
|
||||||
|
Coin string `json:"coin"`
|
||||||
|
|
||||||
DbState uint32 `json:"dbState"`
|
DbState uint32 `json:"dbState"`
|
||||||
|
|
||||||
LastStore time.Time `json:"lastStore"`
|
LastStore time.Time `json:"lastStore"`
|
||||||
|
|
|
@ -875,7 +875,7 @@ func (d *RocksDB) DeleteTx(txid string) error {
|
||||||
const internalStateKey = "internalState"
|
const internalStateKey = "internalState"
|
||||||
|
|
||||||
// LoadInternalState loads from db internal state or initializes a new one if not yet stored
|
// 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))
|
val, err := d.db.GetCF(d.ro, d.cfh[cfDefault], []byte(internalStateKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -884,12 +884,19 @@ func (d *RocksDB) LoadInternalState() (*common.InternalState, error) {
|
||||||
data := val.Data()
|
data := val.Data()
|
||||||
var is *common.InternalState
|
var is *common.InternalState
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
is = &common.InternalState{}
|
is = &common.InternalState{Coin: rpcCoin}
|
||||||
} else {
|
} else {
|
||||||
is, err = common.UnpackInternalState(data)
|
is, err = common.UnpackInternalState(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// make sure that column stats match the columns
|
||||||
sc := is.DbColumns
|
sc := is.DbColumns
|
||||||
|
|
Loading…
Reference in New Issue