put prune switch into usage
This commit is contained in:
parent
4885445735
commit
a098285a7b
|
@ -18,6 +18,7 @@ type
|
|||
# debt while setting a CI baseline from which to improve/replace.
|
||||
accountCodes*: TableRef[Hash256, ByteRange]
|
||||
# TODO db*: JournalDB
|
||||
pruneTrie*: bool
|
||||
|
||||
KeyType = enum
|
||||
blockNumberToHash
|
||||
|
@ -27,10 +28,11 @@ type
|
|||
blockNumber: BlockNumber
|
||||
index: int
|
||||
|
||||
proc newBaseChainDB*(db: TrieDatabaseRef): BaseChainDB =
|
||||
proc newBaseChainDB*(db: TrieDatabaseRef, pruneTrie: bool): BaseChainDB =
|
||||
new(result)
|
||||
result.db = db
|
||||
result.accountCodes = newTable[Hash256, ByteRange]()
|
||||
result.pruneTrie = pruneTrie
|
||||
|
||||
proc `$`*(db: BaseChainDB): string =
|
||||
result = "BaseChainDB"
|
||||
|
@ -275,7 +277,7 @@ proc persistBlockToDb*(self: BaseChainDB; blk: Block) =
|
|||
|
||||
proc getStateDb*(self: BaseChainDB; stateRoot: Hash256; readOnly: bool = false): AccountStateDB =
|
||||
# TODO: readOnly is not used.
|
||||
result = newAccountStateDB(self.db, stateRoot, readOnly, self.accountCodes)
|
||||
result = newAccountStateDB(self.db, stateRoot, self.pruneTrie, readOnly, self.accountCodes)
|
||||
|
||||
|
||||
# Deprecated:
|
||||
|
|
|
@ -25,10 +25,10 @@ proc rootHash*(accountDb: AccountStateDB): KeccakHash =
|
|||
# TODO: self.Trie.rootHash = value
|
||||
|
||||
proc newAccountStateDB*(backingStore: TrieDatabaseRef,
|
||||
root: KeccakHash, readOnly: bool = false,
|
||||
root: KeccakHash, pruneTrie: bool, readOnly: bool = false,
|
||||
accountCodes = newTable[Hash256, ByteRange]()): AccountStateDB =
|
||||
result.new()
|
||||
result.trie = initSecureHexaryTrie(backingStore, root)
|
||||
result.trie = initSecureHexaryTrie(backingStore, root, pruneTrie)
|
||||
result.accountCodes = accountCodes
|
||||
|
||||
template createRangeFromAddress(address: EthAddress): ByteRange =
|
||||
|
|
|
@ -66,10 +66,10 @@ proc defaultGenesisBlockForNetwork*(id: PublicNetwork): Genesis =
|
|||
result.config = publicChainConfig(id)
|
||||
|
||||
proc toBlock*(g: Genesis, db: BaseChainDB = nil): BlockHeader =
|
||||
let tdb = if db.isNil: newMemoryDB()
|
||||
else: db.db
|
||||
let (tdb, pruneTrie) = if db.isNil: (newMemoryDB(), true)
|
||||
else: (db.db, db.pruneTrie)
|
||||
var trie = initHexaryTrie(tdb)
|
||||
var sdb = newAccountStateDB(tdb, trie.rootHash)
|
||||
var sdb = newAccountStateDB(tdb, trie.rootHash, pruneTrie)
|
||||
|
||||
for address, account in g.alloc:
|
||||
sdb.setAccount(address, newAccount(account.nonce, account.balance))
|
||||
|
|
|
@ -74,7 +74,7 @@ proc start(): NimbusObject =
|
|||
|
||||
createDir(conf.dataDir)
|
||||
let trieDB = trieDB newChainDb(conf.dataDir)
|
||||
let chainDB = newBaseChainDB(trieDB)
|
||||
let chainDB = newBaseChainDB(trieDB, conf.prune == PruneMode.Full)
|
||||
|
||||
if canonicalHeadHashKey().toOpenArray notin trieDB:
|
||||
initializeEmptyDb(chainDb)
|
||||
|
|
|
@ -118,7 +118,7 @@ method persistBlocks*(c: Chain, headers: openarray[BlockHeader], bodies: openarr
|
|||
for i in 0 ..< headers.len:
|
||||
let head = c.db.getCanonicalHead()
|
||||
assert(head.blockNumber == headers[i].blockNumber - 1)
|
||||
var stateDb = newAccountStateDB(c.db.db, head.stateRoot)
|
||||
var stateDb = newAccountStateDB(c.db.db, head.stateRoot, c.db.pruneTrie)
|
||||
var gasReward = 0.u256
|
||||
|
||||
assert(bodies[i].transactions.calcTxRoot == headers[i].txRoot)
|
||||
|
|
Loading…
Reference in New Issue