fix contract code retrieval from db

This commit is contained in:
andri lim 2020-04-29 12:12:24 +07:00
parent 4974ca49db
commit c325ce1863
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 6 additions and 4 deletions

View File

@ -2,7 +2,8 @@ import
randutils, stew/byteutils, random,
eth/[common, rlp], eth/trie/[hexary, db, trie_defs],
faststreams/input_stream, nimcrypto/[utils, sysrand],
../stateless/[witness_from_tree, tree_from_witness]
../stateless/[witness_from_tree, tree_from_witness],
../nimbus/db/storage_types
type
DB = TrieDatabaseRef
@ -22,7 +23,7 @@ proc randCode(db: DB): Hash256 =
let codeLen = rand(1..150)
let code = randList(byte, rng(0, 255), codeLen, unique = false)
result = hexary.keccak(code)
db.put(result.data, code)
db.put(contractHashKey(result).toOpenArray, code)
proc randStorage(db: DB): Hash256 =
if rand(0..1) == 0:

View File

@ -3,7 +3,8 @@ import
nimcrypto/[keccak, hash], eth/[common, rlp],
eth/trie/[trie_defs, nibbles, db],
faststreams/output_stream,
./witness_types, ../nimbus/constants
./witness_types, ../nimbus/constants,
../nimbus/db/storage_types
type
DB = TrieDatabaseRef
@ -123,7 +124,7 @@ proc writeAccountNode(wb: var WitnessBuilder, acc: Account, nibbles: NibblesSeq,
if accountType == ExtendedAccountType:
if acc.codeHash != blankStringHash:
let code = get(wb.db, acc.codeHash.data)
let code = get(wb.db, contractHashKey(acc.codeHash).toOpenArray)
if code.len > EIP170_CODE_SIZE_LIMIT:
raise newException(ValueError, "code len exceed EIP170 code size limit")
wb.writeU32(code.len.uint32)