Merge pull request #2215 from nspcc-dev/getproof-fix

rpc: make `getproof` work with destroyed contracts
This commit is contained in:
Roman Khimov 2021-10-15 11:42:06 +03:00 committed by GitHub
commit ab3df6cc52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 3 deletions

View file

@ -406,4 +406,38 @@ func TestCompatibility_Find(t *testing.T) {
t.Run("from matching start", func(t *testing.T) { t.Run("from matching start", func(t *testing.T) {
check(t, []byte{}, 2) // without `from` key check(t, []byte{}, 2) // without `from` key
}) })
t.Run("TestFindStatesIssue652", func(t *testing.T) {
tr := NewTrie(nil, false, newTestStore())
// root is an extension node with key=abc; next=branch
require.NoError(t, tr.Put([]byte("abc1"), []byte("01")))
require.NoError(t, tr.Put([]byte("abc3"), []byte("02")))
tr.Flush()
// find items with extension's key prefix
t.Run("from > start", func(t *testing.T) {
res, err := tr.Find([]byte("ab"), []byte("d2"), 100)
require.NoError(t, err)
// nothing should be found, because from[0]=`d` > key[2]=`c`
require.Equal(t, 0, len(res))
})
t.Run("from < start", func(t *testing.T) {
res, err := tr.Find([]byte("ab"), []byte("b2"), 100)
require.NoError(t, err)
// all items should be included into the result, because from[0]=`b` < key[2]=`c`
require.Equal(t, 2, len(res))
})
t.Run("from and start have common prefix", func(t *testing.T) {
res, err := tr.Find([]byte("ab"), []byte("c"), 100)
require.NoError(t, err)
// all items should be included into the result, because from[0] == key[2]
require.Equal(t, 2, len(res))
})
t.Run("from equals to item key", func(t *testing.T) {
res, err := tr.Find([]byte("ab"), []byte("c1"), 100)
require.NoError(t, err)
require.Equal(t, 1, len(res))
})
})
} }

View file

@ -991,9 +991,9 @@ func (s *Server) getProof(ps request.Params) (interface{}, *response.Error) {
if err != nil { if err != nil {
return nil, response.ErrInvalidParams return nil, response.ErrInvalidParams
} }
cs := s.chain.GetContractState(sc) cs, respErr := s.getHistoricalContractState(root, sc)
if cs == nil { if respErr != nil {
return nil, response.ErrInvalidParams return nil, respErr
} }
skey := makeStorageKey(cs.ID, key) skey := makeStorageKey(cs.ID, key)
proof, err := s.chain.GetStateModule().GetStateProof(root, skey) proof, err := s.chain.GetStateModule().GetStateProof(root, skey)