fixes wrong usage of `chainId` in places where it should be networkId

fixes #643
This commit is contained in:
jangko 2021-05-12 08:55:48 +07:00
parent 2d3d450075
commit f6a0e4bcbd
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
5 changed files with 11 additions and 10 deletions

View File

@ -17,6 +17,7 @@ type
db* : TrieDatabaseRef
pruneTrie*: bool
config* : ChainConfig
networkId*: PublicNetwork
# startingBlock, currentBlock, and highestBlock
# are progress indicator
@ -33,6 +34,7 @@ proc newBaseChainDB*(db: TrieDatabaseRef, pruneTrie: bool = true, id: PublicNetw
result.db = db
result.pruneTrie = pruneTrie
result.config = publicChainConfig(id)
result.networkId = id
proc `$`*(db: BaseChainDB): string =
result = "BaseChainDB"

View File

@ -93,8 +93,7 @@ proc newChain*(db: BaseChainDB): Chain =
if not db.config.daoForkSupport:
db.config.daoForkBlock = db.config.homesteadBlock
let chainId = PublicNetwork(db.config.chainId)
let g = defaultGenesisBlockForNetwork(chainId)
let g = defaultGenesisBlockForNetwork(db.networkId)
result.blockZeroHash = g.toBlock.blockHash
let genesisCRC = crc32(0, result.blockZeroHash.data)
result.forkIds = calculateForkIds(db.config, genesisCRC)

View File

@ -87,7 +87,7 @@ proc traceTransaction*(chainDB: BaseChainDB, header: BlockHeader,
memoryDB = newMemoryDB()
captureDB = newCaptureDB(chainDB.db, memoryDB)
captureTrieDB = trieDB captureDB
captureChainDB = newBaseChainDB(captureTrieDB, false, PublicNetWork(chainDB.config.chainId)) # prune or not prune?
captureChainDB = newBaseChainDB(captureTrieDB, false, chainDB.networkId) # prune or not prune?
vmState = newBaseVMState(parent.stateRoot, header, captureChainDB, tracerFlags + {EnableAccount})
var stateDb = vmState.accountDb
@ -155,7 +155,7 @@ proc dumpBlockState*(db: BaseChainDB, header: BlockHeader, body: BlockBody, dump
memoryDB = newMemoryDB()
captureDB = newCaptureDB(db.db, memoryDB)
captureTrieDB = trieDB captureDB
captureChainDB = newBaseChainDB(captureTrieDB, false, PublicNetWork(db.config.chainId))
captureChainDB = newBaseChainDB(captureTrieDB, false, db.networkId)
# we only need stack dump if we want to scan for internal transaction address
vmState = newBaseVMState(parent.stateRoot, header, captureChainDB, {EnableTracing, DisableMemory, DisableStorage, EnableAccount})
miner = vmState.coinbase()
@ -212,7 +212,7 @@ proc traceBlock*(chainDB: BaseChainDB, header: BlockHeader, body: BlockBody, tra
memoryDB = newMemoryDB()
captureDB = newCaptureDB(chainDB.db, memoryDB)
captureTrieDB = trieDB captureDB
captureChainDB = newBaseChainDB(captureTrieDB, false, PublicNetWork(chainDB.config.chainId))
captureChainDB = newBaseChainDB(captureTrieDB, false, chainDB.networkId)
vmState = newBaseVMState(parent.stateRoot, header, captureChainDB, tracerFlags + {EnableTracing})
if header.txRoot == BLANK_ROOT_HASH: return newJNull()
@ -246,7 +246,7 @@ proc dumpDebuggingMetaData*(chainDB: BaseChainDB, header: BlockHeader,
memoryDB = newMemoryDB()
captureDB = newCaptureDB(chainDB.db, memoryDB)
captureTrieDB = trieDB captureDB
captureChainDB = newBaseChainDB(captureTrieDB, false, PublicNetWork(chainDB.config.chainId))
captureChainDB = newBaseChainDB(captureTrieDB, false, chainDB.networkId)
bloom = createBloom(vmState.receipts)
let blockSummary = %{

View File

@ -69,9 +69,9 @@ proc setupTxContext*(vmState: BaseVMState, origin: EthAddress, gasPrice: GasInt,
vmState.gasCosts = vmState.fork.forkToSchedule
proc consensusEnginePoA*(vmState: BaseVMState): bool =
let chainId = PublicNetwork(vmState.chainDB.config.chainId)
let networkId = vmState.chainDB.networkId
# PoA consensus engine have no reward for miner
result = chainId in {GoerliNet, RinkebyNet, KovanNet}
result = networkId in {GoerliNet, RinkebyNet, KovanNet}
proc getSignature(bytes: openArray[byte], output: var Signature): bool =
let sig = Signature.fromRaw(bytes)

View File

@ -57,9 +57,9 @@ proc newBaseVMState*(prevStateRoot: Hash256,
result.init(prevStateRoot, header, chainDB, tracerFlags)
proc consensusEnginePoA*(vmState: BaseVMState): bool =
let chainId = PublicNetwork(vmState.chainDB.config.chainId)
let networkId = vmState.chainDB.networkId
# PoA consensus engine have no reward for miner
result = chainId in {GoerliNet, RinkebyNet, KovanNet}
result = networkId in {GoerliNet, RinkebyNet, KovanNet}
proc getSignature(bytes: openArray[byte], output: var Signature): bool =
let sig = Signature.fromRaw(bytes)