Repository navigation
Commit 0b93e66
fix(seidb): keep the memIAVL nonce when state sync restores a mid-mig… (#4463)
## Summary
State sync from a snapshot taken during the last phase of the EVM
migration writes nonce 0 over the real nonce of contracts in the state
store (SS). This PR stops the SS import from writing a zero nonce from a
FlatKV account row. Only the SS import path changes. State commitment,
the snapshot format, and the AppHash are unchanged, so the fix is safe
for a v6.7.x patch.
The window: the migration moves keys in key order, so all 0x08 (code
hash) keys move before any 0x0a (nonce) key. FlatKV stores the nonce and
the code hash in one account row. Between the two prefixes, each
contract has a FlatKV row with a correct code hash and nonce 0, while
its real nonce is still in memIAVL. The snapshot puts the memIAVL
sections first and the FlatKV section after them. So on import the SS
gets the real nonce first, and then a zero nonce from the FlatKV row
that overwrites it. The wrong value stays until a transaction writes
that nonce again. Non-pending `eth_getTransactionCount`, `eth_call` and
`eth_estimateGas` for contract-creating calls, and `debug_trace*` read
it.
- `sei-db/state_db/ss/composite/store.go`: `convertFlatKVNodes` now
omits a zero nonce from a merged account row, the same way it already
omits a zero code hash. A non-zero FlatKV nonce is never stale:
`shouldForwardWriteToNewDB` sends each write to the database that holds
the key, and a migrated key is deleted from memIAVL, so the two backends
never both hold a valid nonce for one address. An absent nonce reads as
0 in `Keeper.GetNonce`, `DBImpl.Exist`, and `DBImpl.Empty`.
- After state sync, an account with nonce 0 has no nonce key in the SS,
but a node that replays blocks can hold 8 zero bytes. Point reads return
the same value. A raw scan such as `IterateAllNonces` skips those
accounts.
- Backport to `release/v6.7`: on that branch
`CompositeCommitStore.Commit` takes no argument, so the two
`cs.Commit(cs.Version() + 1)` calls in `import_migration_test.go` become
`cs.Commit()`.
## Test plan
- `sei-db/state_db/ss/composite/store_test.go`
- `TestImport_FlatKVZeroNonceKeepsMemIAVLNonce`: the stream holds a
memIAVL nonce (5) and then a FlatKV account row with nonce 0 and a code
hash. The SS keeps nonce 5 and stores the code hash, with `EVMSplit`
true and false.
- `TestImport_FlatKVZeroNonceIsAbsent`: a FlatKV account row with nonce
0 alone leaves no nonce key in the SS.
- `sei-db/state_db/ss/composite/import_migration_test.go`
- `TestImport_MidMigrationSnapshotRestoresNonce`: builds a real
mid-migration commit store (MemiavlOnly commit, then `MigrateEVM` with
batch size 1) and exports a snapshot. It asserts that the stream holds
both the memIAVL nonce and the FlatKV account row, then imports it into
the cosmos, evm-split, and evm-separate-sub-dbs SS layouts and checks
the nonce and the code hash.
- Without the `nonce != 0` guard, all three tests fail. With it, they
pass.
- `scripts/ramtest.sh ./sei-db/state_db/ss/... ./sei-cosmos/storev2/...
-count=1` passes, and `-race` on `ss/composite` `TestImport*` passes.
- `make fmtcheck` and `make dblint` are clean.
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent dced959 commit 0b93e66
3 files changed
Lines changed: 219 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
481 | | - | |
482 | | - | |
483 | | - | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
484 | 484 | | |
485 | 485 | | |
486 | 486 | | |
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
526 | | - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
527 | 530 | | |
528 | 531 | | |
529 | 532 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1165 | 1165 | | |
1166 | 1166 | | |
1167 | 1167 | | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
1168 | 1234 | | |
1169 | 1235 | | |
1170 | 1236 | | |
| |||
0 commit comments