Skip to content

Conversation

haikoschol
Copy link
Contributor

Changes

This PR should cover all changes mentioned in the issue, except for changing StorageState.Entries() to return a statemachine.PairsIter. As we discussed on Slack, this will be postponed since it is only used in RPC, which is currently not a priority.

Regarding LoadCode(); The implementation on ClientAdapter expects a block hash as the argument. The current implementation in state.InMemoryStorageState calls GetStorage(), which expects a state root hash. I'm pretty sure this is a long existing bug that hasn't been noticed because LoadCode() is called with nil on startup, which defaults to the best block.

Tests

go test github.com/ChainSafe/gossamer/internal/client/adapter

Issues

#4467

Copy link
Contributor

@dimartiro dimartiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but there are some things we can check or / and change before merging

}

h := common.NewHashFromGeneric((*header).StateRoot())
return &h, nil
}

func (ca *ClientAdapter[H, Hasher, N, E, Header]) GenerateTrieProof(stateRoot common.Hash, keys [][]byte) (
[][]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why this is still unimplemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally the answer to that question was because I overlooked it. Now the answer is because I don't know how. 😅 Looking at the old implementation hasn't helped so far.

I also overlooked StorageState.TrieState(), which I've implemented here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use NewMerkleProof

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimartiro thanks for pointing me towards NewMerkleProof(). There's just one issue; it expects a hashdb.HashDB and all i have is a ClientAdapterDB and a statemachine.Backend.

@haikoschol haikoschol force-pushed the haiko/read-only-storage-state branch from 7d9bbab to 37dd38d Compare June 20, 2025 08:47
@haikoschol haikoschol requested a review from dimartiro June 23, 2025 15:20
func (ca *ClientAdapter[H, Hasher, N, E, Header]) GetRoundAndSetID() (uint64, uint64) {
panic("unimplemented")
}

func (ca *ClientAdapter[H, Hasher, N, E, Header]) GetRuntime(blockHash common.Hash) (instance rt.Instance, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should implement this in some point if we want to achieve a full read-only shim type. Do we have an issue for this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it part of #4807?

@@ -63,6 +63,7 @@ var (
statemachine.Backend[hash.H256, runtime.BlakeTwo256], any,
*generic.Header[uint64, hash.H256, runtime.BlakeTwo256],
]] = &TestClient{}
_ api.StorageProvider[hash.H256, runtime.BlakeTwo256] = &TestClient{}
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can add more tests cases here since you added the api.StorageProvider implementation for Client

After #4792, StorageState methods that expected a state root hash now
take a block hash. This updates all affected StorageState methods on
ClientAdapter and simplifies their implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants