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

View File

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

View File

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

View File

@ -69,9 +69,9 @@ proc setupTxContext*(vmState: BaseVMState, origin: EthAddress, gasPrice: GasInt,
vmState.gasCosts = vmState.fork.forkToSchedule vmState.gasCosts = vmState.fork.forkToSchedule
proc consensusEnginePoA*(vmState: BaseVMState): bool = 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 # 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 = proc getSignature(bytes: openArray[byte], output: var Signature): bool =
let sig = Signature.fromRaw(bytes) let sig = Signature.fromRaw(bytes)

View File

@ -57,9 +57,9 @@ proc newBaseVMState*(prevStateRoot: Hash256,
result.init(prevStateRoot, header, chainDB, tracerFlags) result.init(prevStateRoot, header, chainDB, tracerFlags)
proc consensusEnginePoA*(vmState: BaseVMState): bool = 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 # 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 = proc getSignature(bytes: openArray[byte], output: var Signature): bool =
let sig = Signature.fromRaw(bytes) let sig = Signature.fromRaw(bytes)