Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: storage root mismatch at block 1789153 #4189

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions lib/runtime/wazero/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1339,3 +1339,67 @@ func TestInstance_GrandpaSubmitReportEquivocationUnsignedExtrinsic(t *testing.T)
err = runtime.GrandpaSubmitReportEquivocationUnsignedExtrinsic(equivocationProof, opaqueKeyOwnershipProof)
require.NoError(t, err)
}

func newTrieFromKeyValueListV1(t *testing.T, filename string) trie.Trie {
data, err := os.ReadFile(filename)
require.NoError(t, err)

stateTrieResponse := make([]string, 0)
err = json.Unmarshal(data, &stateTrieResponse)
require.NoError(t, err)

entries := make(map[string]string)
for _, encEntry := range stateTrieResponse {
entry := new(trie.Entry)
err := scale.Unmarshal(common.MustHexToBytes(encEntry), entry)
require.NoError(t, err)

entries[common.BytesToHex(entry.Key)] = common.BytesToHex(entry.Value)
}

tr, err := inmemory_trie.LoadFromMap(entries, trie.V1)
require.NoError(t, err)
return tr
}

func TestInstance_ExecuteBlock_PaseoRuntime_PaseoBlock1789153(t *testing.T) {
paseoTrie := newTrieFromKeyValueListV1(t, "../test_data/paseo/block1789152.out")
expectedRoot := common.MustHexToHash("0xf74a4a94758ac505a0bacdd52d7739d62b616eb03840d24d4a2df42df295c31d")
require.Equal(t, expectedRoot, trie.V1.MustHash(paseoTrie))

//paseoTrieActual := newTrieFromKeyValueListV1(t, "../test_data/paseo/block1789153.out")
//expectedRootActual := common.MustHexToHash("0xc29a9d4465400c980cca388963461755040f2ba4c5ed722afc204014426e9080")
////require.Equal(t, expectedRootActual, trie.V1.MustHash(paseoTrieActual))

state := storage.NewTrieState(paseoTrie)
db, err := database.NewPebble("", true)
require.NoError(t, err)

cfg := Config{
Storage: state,
LogLvl: log.Critical,
NodeStorage: runtime.NodeStorage{
LocalStorage: db,
PersistentStorage: db,
BaseDB: db,
},
}

instance, err := NewInstanceFromTrie(paseoTrie, cfg)
require.NoError(t, err)

blockResponse := &messages.BlockResponseMessage{}
err = blockResponse.Decode(common.MustHexToBytes("0x0a980f0a2000ab8c6e55a9951698052d9d999eb0c440c525af05867df39cb55863632b4ad912c702dacf47ace27c5ea78dc8dd9b3e22b02fef70865663511c8dc625c682adb92e7b86336d00c29a9d4465400c980cca388963461755040f2ba4c5ed722afc204014426e9080804403dad405e595bdca5f068ae91a75d455c90f3e7672a2ee62d3b506a93c210c0642414245b501012d00000080411411000000004cdbdb6fad62ab658029ea5891097221601991b27937b7d5d5631977e6eed1403aca4e0969fca166cd9442090a19800960743275ccde702ceb2380ca03a1410c4cbcb30f76e438b4f373f4d11f0e962717d993f8d5875f704bb62b1833b86b0a04424545468403e27785a60c1caf697109d8e173e3885432223ae08cc3a7736cb47578672228800542414245010174ee1ef2749cf4c906e7451df6f4c437e1c28cf43cde73e1ea0b20fa2e6b253559991104b5cb0ee7e89878bbf266c41a79609c9bb342d0ecd66b5cabd8abbb821a0b280403000b0028bf4a90011a9c0c69180436001c404082040000003c1c2072fc87375e6fb060fa2c4d2e2bb5e49655a4085ce81e9f38b4f8fc0c27b38aed1a2b14ce90ae52f299659b7e05d8e7a36f502b8b4e6b0b51bdee39b8864040820a00000046b4b8d09b32f8733851d3c52e1755baf47cdf94178d6d41f1046e7b27d24d20e5bd457dc11779174693cdca461ef5a554ab5aebc7b240f7e7dabb63db81eb8c4040821200000034780d63fe628c9ed70cfe4bf9bccab95885f7ad7dc8c9ef5c8bbf4c0ed4c7737e66975f5e36863a37847449a9bdd265c33473dd01c66d2eb6df56e2b54aee8c404082200000002c5e506d505990ef37036887292fea85e545f45c477512699fb209ce07f0085536b57a0b9eba6dc265134a2fc9548b72c2ed762c0d0e749cc40f4bb6fbf83a8d40408221000000f03f3ee19ecc74666b6733a57799ab73b50c1ede5df201e11849284b20b21a269bc18454d5b715e5a6bfbd454b37d39626db1bcb33bac1c78ab793680d42c3824040823200000024038d3803c9bfce4221c59913037affe5f7f67e2c85da9ae22a7de1a2b84315cc842618492e1157fa344b350840d3b451f1a17b863037c4f7f963c3c136158d40408233000000c2a2489e88287315fb5660ac8d614c90acb161acaa027f02640bfd647a4bcb01a33ca7efab99da38e12121f10294edf2f203a6d3c23b40b9bfb64215c2b0bb8204df070000dacf47ace27c5ea78dc8dd9b3e22b02fef70865663511c8dc625c682adb92e7b1421bbd8065689fbffd0015ec824862c247c74efb81d7097c8916ce538d1000a6da866424c6851d32a2dec2a17af4895b439f48bcbd15e8bd29cb90dc36881b1cadb7a887993a9d0389947e10fe20354e3e4bcd288589d5227b4882414f11c73414a850a6eea37caa076d56c409108f259982204b35471ccdc77d15343afd8ae661d3dd5391a9939cd36c2b50a174a4639ae726e27a39555892e401b84341754b6d8e34c5047efeb00080de9223931f3806f09642aae5765317d76103907898e3dfd7cc6839082ac61c25874fd304aa9f04c9c6ab22669007b9779d018f754fded4acef6aaa37f3d19eb3318fa5a9b62188ea2e488b2cb9a0af895ef496703c80000009103530676dcbb08f5a82b835bd38ab0fe7da0644dee97dd315291ad75b55a340261e652220076cf83e15e80a19af5bcaea0785d4e48d229cdf5dd153864350478f15087f57d04f99b61a2da580b7a37ca571fc01082ce68442eeb908b379f07ae44b9046fcc0c066175726120bf208a0800000000045250535290f74a4a94758ac505a0bacdd52d7739d62b616eb03840d24d4a2df42df295c31d82336d0005617572610101da85d66ac9895ad47f17997a74dc59b702b508eabdb102df271937688041d842f1c824c1cbc7e5ae703d761043b472c383e4712f7cac6b401dadf7530c5a3c8000000000e04c1b000c01fe7447034f72f3147c7f8f597acc64e9a451976dccc44222e9bf4490980d7b546f4341e563634c0e121bf2520381c35ed28746afc8904904fce2fba1551a4d8001364d7f7c48ae3e22d558a0b940ae51225dacc714950d322ed03733adb6c4be442a946caff686b716b605acf529ff7353f279efb104960a8fbf8433851b8ec88902844ccafbb3dae450f7c9bb870167d69b5d76a44ac975539da3b8d9ff908a6e2489d61daf3f2db5e188a235db74ea5d65eea9c9fbfd06e6c068f2abef52781e8610070089dbf7d702484000b3b22f06e497e4b1babeebdebffd34104e7becda11f77ada82336d00f74a4a94758ac505a0bacdd52d7739d62b616eb03840d24d4a2df42df295c31d6a489ada4a1a7e60a4418b0e7e9c037f21096d55e71dd479fa06c2fcc2893ed3100642414245b50103140000007f41141100000000a61518d94943fdb3099b7152ae8853406b43181d4323902010619ce327c8241a7bac1d6623d1bcf08c1579db3ea6a192ddafd0177c936808eccdec4892f47007d2b4c93b9ee38019acf47b272474ab31ee2f9e905fe6d52a43cb4de1018a4a00044245454684039b9b32499e519a43c1242be468073cce8a7b70604bd1766706bea09cd66889d70805424142450101b83da521999ad8d04448cf4aea523f4ecd32e9ad568daf47d9e02811408b8817f85e7865018512510f6da3fe0cce92a173622b3411fcff81802e3d7316cbd58e")) //nolint:lll
require.NoError(t, err)

block := &types.Block{
Header: *blockResponse.BlockData[0].Header,
Body: *blockResponse.BlockData[0].Body,
}

_, err = instance.ExecuteBlock(block)
require.NoError(t, err)

expectedRootNew := common.MustHexToHash("0xc29a9d4465400c980cca388963461755040f2ba4c5ed722afc204014426e9080")
require.Equal(t, expectedRootNew, state.Trie().MustHash())
}
Loading