KomodoPlatform / zebra

An ongoing Rust implementation of a Komodo node. 🦓
Apache License 2.0
3 stars 5 forks source link

Rule to prevent forks from below last notarised height #10

Closed dimxy closed 1 year ago

dimxy commented 1 year ago

Add a rule matching the same rule in komodod ActivateBestChainStep(): if an activated chain fork grows from below the last notarised height disable such chain fork activation and reject the new connecting block if any.

dimxy commented 1 year ago

added in PR #2 commit 910bf4da00bc9761e826936e9150fc89b2baa29e

dimxy commented 1 year ago

I did more research and made another test block set to check komodo_check_fork_is_valid() function and found that it fails if a new forked chain contains a nota. This happens because the nota in the new chain becomes the 'latest nota' and komodo_check_fork_is_valid() can find that the fork point may be below the last notarized height (if the fork point is deep enough). This happens because komodod and zebra work differently: komodod processes notas only when a chain is activated (so notas in new chains are not known until the chain is activated) but zebra processes notas whenever any block is added. I added a condition into komodo_check_fork_is_valid(): if the new chain contains a nota this chain is considered as valid. I think this should work all right: a chain with nota should be always valid the fix: 73fb0cac68191a9ffc5c7b1ded23577908b1981f

dimxy commented 1 year ago

Note that this issue is different from the issue #34 rule which purpose is also to prevent forks below the last notarized height. This rule and the issue 34 rule complement each other (as they both do in komodod):

dimxy commented 1 year ago

Now I think that the current implementation of fork prevention mechanism in zebra, when best_chain only selects the branch with most PoW, is not perfect because it may temporarily allow to have a best chain without nota (if the best chain was built before the fork with a nota came in). So we need to fix best_chain() function to make it to select a chain not only with most power but with a nota in it

dimxy commented 1 year ago

TODO: fix best_chain() to check if it has last nota

dimxy commented 1 year ago

finally fixed and closed in #45