2019-02-26 18:40:17 +00:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/boltdb/bolt"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2019-02-28 03:55:47 +00:00
|
|
|
"go.opencensus.io/trace"
|
2019-02-26 18:40:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var depositContractAddressKey = []byte("deposit-contract")
|
|
|
|
|
|
|
|
// VerifyContractAddress that represents the data in this database. The
|
|
|
|
// contract address is the address of the deposit contract on the proof of work
|
|
|
|
// Ethereum chain. This value will never change or all of the data in the
|
|
|
|
// database would be made invalid.
|
|
|
|
func (db *BeaconDB) VerifyContractAddress(ctx context.Context, addr common.Address) error {
|
2019-02-28 03:55:47 +00:00
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.VerifyContractAddress")
|
|
|
|
defer span.End()
|
2019-02-26 18:40:17 +00:00
|
|
|
|
|
|
|
return db.update(func(tx *bolt.Tx) error {
|
|
|
|
chainInfo := tx.Bucket(chainInfoBucket)
|
|
|
|
|
|
|
|
expectedAddress := chainInfo.Get(depositContractAddressKey)
|
|
|
|
if expectedAddress == nil {
|
|
|
|
return chainInfo.Put(depositContractAddressKey, addr.Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(expectedAddress, addr.Bytes()) {
|
2019-04-23 20:52:52 +00:00
|
|
|
return fmt.Errorf("invalid deposit contract address, expected %#x - try running with --clear-db", expectedAddress)
|
2019-02-26 18:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|