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()
|
||||
|
||||
common.IS, err = index.LoadInternalState()
|
||||
common.IS, err = index.LoadInternalState(*coin)
|
||||
if err != nil {
|
||||
glog.Fatal("internalState: ", err)
|
||||
}
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue