Skip to content

Commit

Permalink
feat: add upgrade config for security enhancement (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing authored Jul 6, 2023
1 parent 33000bc commit fbbe37a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions store/iavlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type IavlStore struct {
// By default this value should be set the same across all nodes,
// so that nodes can know the waypoints their peers store.
storeEvery int64

diff map[string]struct{}
}

// CONTRACT: tree should be fully loaded.
Expand All @@ -63,6 +65,7 @@ func newIAVLStore(tree *iavl.MutableTree, numRecent int64, storeEvery int64) *Ia
Tree: tree,
numRecent: numRecent,
storeEvery: storeEvery,
diff: nil,
}
return st
}
Expand All @@ -71,6 +74,10 @@ func (st *IavlStore) GetImmutableTree() *iavl.ImmutableTree {
return st.Tree.ImmutableTree
}

func (st *IavlStore) GetTree() *iavl.MutableTree {
return st.Tree
}

func (st *IavlStore) SetVersion(version int64) {
st.Tree.SetVersion(version)
}
Expand Down Expand Up @@ -147,6 +154,9 @@ func (st *IavlStore) CacheWrapWithTrace(w io.Writer, tc TraceContext) CacheWrap
// Implements KVStore.
func (st *IavlStore) Set(key, value []byte) {
st.Tree.Set(key, value)
if st.diff != nil {
st.diff[string(key)] = struct{}{}
}
}

// Implements KVStore.
Expand All @@ -155,6 +165,18 @@ func (st *IavlStore) Get(key []byte) (value []byte) {
return v
}

func (st *IavlStore) EnableDiff() {
st.diff = map[string]struct{}{}
}

func (st *IavlStore) GetDiff() map[string]struct{} {
return st.diff
}

func (st *IavlStore) ResetDiff() {
st.diff = map[string]struct{}{}
}

// Implements KVStore.
func (st *IavlStore) Has(key []byte) (exists bool) {
return st.Tree.Has(key)
Expand All @@ -163,6 +185,9 @@ func (st *IavlStore) Has(key []byte) (exists bool) {
// Implements KVStore.
func (st *IavlStore) Delete(key []byte) {
st.Tree.Remove(key)
if st.diff != nil {
st.diff[string(key)] = struct{}{}
}
}

// Implements KVStore
Expand Down
2 changes: 1 addition & 1 deletion types/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
BEP173 = "BEP173" // https://github.com/bnb-chain/BEPs/pull/173
FixDoubleSignChainId = "FixDoubleSignChainId"
BEP126 = "BEP126" //https://github.com/binance-chain/BEPs/pull/126

BEP255 = "BEP255" // https://github.com/bnb-chain/BEPs/pull/255
)

var MainNetConfig = UpgradeConfig{
Expand Down

0 comments on commit fbbe37a

Please sign in to comment.