-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor code #11
Refactor code #11
Conversation
It is an impressive implementation! I think there are some things we need to check more. Correct me if I am wrong
|
You can test this case by putting
In our case, the block queue used on the block keeper is the circular queue that stores the 64 latest blocks. We assume that after 64 blocks, the chain is immutable
-> So we finish the process of finding the re-orged blocks, we will have the correct queue.
|
@nguyenzung Oh I got your point 2. Let me think about it. You're correct. We should remove the reorged block on the queue not the first element. Good point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nguyenzung many thanks @nguyenzung for your helpful comments
-
The gap between the time we run
syncOldBlocks
function andsubscribeNewHead
can be fixed by the functionhandleReorgedBlocks
by checking whether the parentHash exists on the queue or not. -
I updated the queue by adding the new remove function to remove the element by the value. The purpose of this function is to remove the re-orged block hashes if exist not the first element on the queue.
Also, I initiated the block-keeper to get the latest 64 blocks(2 epochs) when starting the event listener service. The purpose of it is to check the re-org of blocks when starting the event listener from scratch or continue from the starting point.
- I updated the code to ignore the
Removed
log when true
if l.Removed { | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref to 3.
func (q *CircularQueue[T]) RemoveAndEnqueue(value T, removed T) { | ||
q.Remove(removed) | ||
q.Enqueue(value) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref to 2.
for i := uint64(blockNo) - TwoEpochBlocks + 1; i < blockNo; i = i + batchBlocksSize { | ||
from := i | ||
to := i + batchBlocksSize - 1 | ||
if to > blockNo-1 { | ||
to = blockNo - 1 | ||
} | ||
|
||
blocks, err := bcSource.GetBlocks(ctx, false, from, to) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, block := range blocks { | ||
keeper.enqueue(block.Header.Hash(), block.Header.Number.Uint64()) | ||
} | ||
} | ||
|
||
keeper.enqueue(common.HexToHash(currentBlockHash), blockNo) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref to 2.
It looks great, Nam! I think maybe we should have other ticket for UnitTest to make sure everything works well |
I tested the deposit and withdraw transaction successfully on my local
Explorer URL: https://sepolia.etherscan.io/tx/0x9ee609a4919f6d9ac3ce673cac0f2f14776acb29c3eabe5fd169f458b9724f20
How to test my PR?
docker-compose
first to start theredis
instance(redis is used for storing the block synced metadata).env
file