[ETCM-263] improve BlockImport wrt checkpoints - ChainWeight#769
[ETCM-263] improve BlockImport wrt checkpoints - ChainWeight#769
Conversation
| val newBlockNr = block.number | ||
| val nextExpectedBlock = state.lastFullBlockNumber + 1 | ||
|
|
||
| println("CODO KURWY???") |
| def getChainWeightByNumber(blockNumber: BigInt): Option[ChainWeight] = | ||
| getHashByBlockNumber(blockNumber).flatMap(getChainWeightByHash) | ||
|
|
||
| // /** |
|
|
||
| object ChainWeight { | ||
| //FIXME: a shorter name? | ||
| def totalDifficultyOnly(td: BigInt): ChainWeight = |
There was a problem hiding this comment.
hmm totalDifficulty for me looks ok too.
There was a problem hiding this comment.
I'd rather have these extra 4 letters to distinguish from ChainWeight#totalDifficulty
|
|
||
| //Test API | ||
|
|
||
| def increaseTd(td: BigInt): ChainWeight = |
There was a problem hiding this comment.
increaseTd => increaseTotalDifficulty
| ChainWeight(0, 0) | ||
| } | ||
|
|
||
| case class ChainWeight( |
| RLPList( | ||
| protocolVersion, | ||
| networkId, | ||
| //TODO: should it be an RLPList? Should we define encoding in ChainWeight object? |
There was a problem hiding this comment.
👍 for encoding in ChainWeight object but move it to the end or merge both RLPLists into one
There was a problem hiding this comment.
I'm not yet sure how to handle that while keeping the compatibility with v63 messages
| ), | ||
| totalDifficulty, | ||
| latestCheckpointNumber | ||
| //TODO: should it be an RLPList? Should we define encoding in ChainWeight object? |
| ByteString(compactPickledBytesToArray(buffer)) | ||
| } | ||
|
|
||
| def byteSequenceToBuffer(bytes: IndexedSeq[Byte]): ByteBuffer = |
There was a problem hiding this comment.
Can you use it in other KeyValueStorages ?
| <logger name="io.iohk.ethereum.vm.VM" level="OFF" /> | ||
|
|
||
| <root level="INFO"> | ||
| <root level="DEBUG"> |
|
|
||
| peerEventBus.expectMsgClass(classOf[Subscribe]) | ||
| peerEventBus.reply(MessageFromPeer(NewBlock(testBlocks.last, testBlocks.last.number), defaultPeer.id)) | ||
| // It's weird that we're using block number for total difficulty but I'm too scared to fight this dragon |
There was a problem hiding this comment.
This test continues to be the most difficult one to follow, at least among the ones I've dealt with recently
| go(newBlockData :: executedBlocks, remainingBlocks.tail, newWeight, None) | ||
| case Left(executionError) => | ||
| go(executedBlocks, remainingBlocks, 0, Some(executionError)) | ||
| go(executedBlocks, remainingBlocks, parentWeight, Some(executionError)) |
There was a problem hiding this comment.
Instead of parentWeight shouldn't it be parentWeight.increase(blockToExecute.header)? The next block to be executed will be the son of the current one
Although I'm not sure what's the purpose of continuing executing a branch on which one of the blocks failed to be executed
| case (_, Hello.code) => payload.toHello | ||
|
|
||
| //FIXME: I still have an issue with protocolVersion, we are use PV62 and PV63 and code names for Status and NewBlock | ||
| // suggest that there is PV64, but there isn't |
There was a problem hiding this comment.
Hmm now that you say it makes sense to have a PV64
It's weird that ETC has some duplication between the capability from Hello messages and this status field (we even use the same Versions.PV63 variable), but in copying them we should probably have that duplication as well
It might also be worth researching the difference in purposes between the 2 in case we are missing something
There was a problem hiding this comment.
Should we research that as part of 280? Or maybe a separate task?
There was a problem hiding this comment.
Hmm maybe it would be better to make it part of ETCM-280? In order to be sure of the approach we are taking there
We could split it later into more tasks if we detect that it's taking longer than expected
a914015 to
7dd7354
Compare
| storage.persist() | ||
| stateStorage.forcePersist(GenesisDataLoad) | ||
| blockchain.save(Block(header, BlockBody(Nil, Nil)), Nil, header.difficulty, saveAsBestBlock = true) | ||
| // TODO: factory for ChainWeight? |
There was a problem hiding this comment.
you have it already ;) ChainWeight.totalDifficultyOnly
|
|
||
| override def valueDeserializer: IndexedSeq[Byte] => BlockHeader = | ||
| bytes => Unpickle[BlockHeader].fromBytes(ByteBuffer.wrap(bytes.toArray[Byte])) | ||
| byteSequenceToBuffer _ andThen Unpickle[BlockHeader].fromBytes |
There was a problem hiding this comment.
WDYT about creating helper for byteSequenceToBuffer _ andThen Unpickle[Type].fromBytes ?
There was a problem hiding this comment.
I'd prefer to merge it ASAP, but added a TODO
| case (None, None) => | ||
| compareByDifficulty(newBranch, oldBranch) | ||
| case None => | ||
| // TODO: should we log if parentWeight not found? |
There was a problem hiding this comment.
Cause the code would be ugly :) This match doesn't capture the situation - there could be no parent to get the weight for
There was a problem hiding this comment.
Maybe we could change it a bit it to detect that case? More of this logs never bothered, we never know when it will be useful
| def genesisHash: ByteString | ||
| genesisHash: ByteString | ||
| ): Status = | ||
| //TODO: explain, remove if possible |
| def as63: NewBlock63 = | ||
| NewBlock63(block, totalDifficulty) | ||
| def apply(block: Block, chainWeight: ChainWeight): NewBlock = | ||
| //TODO: explain, remove if possible |
ntallar
left a comment
There was a problem hiding this comment.
Last comments, got to take a look at all the changes!
Code is looking much nicer ❤️
| case (None, None) => | ||
| compareByDifficulty(newBranch, oldBranch) | ||
| case None => | ||
| // TODO: should we log if parentWeight not found? |
There was a problem hiding this comment.
Maybe we could change it a bit it to detect that case? More of this logs never bothered, we never know when it will be useful
| case (_, Hello.code) => payload.toHello | ||
|
|
||
| //FIXME: I still have an issue with protocolVersion, we are use PV62 and PV63 and code names for Status and NewBlock | ||
| // suggest that there is PV64, but there isn't |
There was a problem hiding this comment.
Hmm maybe it would be better to make it part of ETCM-280? In order to be sure of the approach we are taking there
We could split it later into more tasks if we detect that it's taking longer than expected
7dd7354 to
5ef06b3
Compare
ntallar
left a comment
There was a problem hiding this comment.
Synced 50k blocks from mordor without any problems! Though I had to fix an issue
| .orElse(newHeaders.headOption) | ||
| .map { header => | ||
| blockchain | ||
| .getChainWeightByHash(header.hash) |
There was a problem hiding this comment.
Shouldn't we fetch here for the header.parentHash? Syncing to mordor fails if not due to ChainWeight for 1 not found when resolving branch
5ef06b3 to
ee341ce
Compare
ntallar
left a comment
There was a problem hiding this comment.
LGTM! Syncing to mordor now works, played a bit around with the mocked miner and qa checkpoints and it all worked
.\\ //.
. \ \ / /.
.\ ,\ /` /,.-
-. \ /'/ / .
` - `-' \ -
'. /.\`
- .-
:`//.'
.`.'
.' BP
ee341ce to
6e722c8
Compare
Description
Improves branch comparison wrt checkpoints during block import
Proposed Solution
Introduces a unified idea of
ChainWeightTesting
Unit tests