Skip to content
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 submission bitcoin status #170

Merged
merged 2 commits into from
Oct 18, 2022

Conversation

KonradStaniec
Copy link
Collaborator

Simplifies btccheckpoint code, by getting rid of different methods checking for submission bitcoin status.

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool simplification! Some comments

}
if err != nil {
// one of blocks is not known to light client
return OnFork, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since OnFork implies that something exists on btc, maybe we can have an extra code Unknown or similar for demonstrating this use case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is we do not handle in any meaningful way submissions which are in blocks not known to lightclient.

They:

  • are not accepted when submitted
  • the should be deleted if they ware accepted, and then forgotten by lightclient (this means they ended on btc fork, and headers were pruned)

Therefore imo it is just one enum case more which we would need to maintain in some way but would not be in any case useful. Thats why it is treated as error.

// counts as unconfirmed submission.
// always start submission lifecycle from unconfirmed state, even if it is
// confirmed or finalized. It will quickly reach next states with btc
// light client blocks
k.addToUnconfirmed(ctx, sk)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can name this addToSubmitted to ensure consistency on names. Also, couldn't we use the submissionBtcState to identify in which state we can add this? I understand that this will finally reach the correct state, but why should we wait for a new BTC block to update the status?

Copy link
Collaborator Author

@KonradStaniec KonradStaniec Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will re-name it 👍

As for second point, we could probably use submissionBtcState to jump directly to correct state, but:

  • It nicer to have every submission to go to through correct state transition path i.e Submitted -> Confirmed -> Finalized
  • Jumping to correct state here would probably means we need more special logic here i.e should be check if this submission confirm/finalised whole epoch, should be clear other submissions if epoch state changes etc. Therefore it is simpler to just treat every submission as submitted at the begnining.

The price for it is of course, that it can decrease latency a bit as we need movement in btclightclient, but it should not be a big deal.

}

return uint64(depth), true, nil
if submissionDepth >= k.GetParams(ctx).CheckpointFinalizationTimeout {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose that the submission is split between blocks N and N+1, and we are at height N+w. Then the submission will be treated as finalized, but block N+1 is not w-deep. Do we consider this acceptable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, it the loop above this code, we calculate submission depth as the depth of its most fresh header. (header with lower depth)

So if one header has depth 10 and another header has depth 20 then depth of submission is 10 so if our confirmation depth is 15, then it that case submission won't be confirmed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thanks for explaining

)

if err != nil {
panic("Headers which are should have been known to btclight client")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Headers which are should ?

// TODO: Either get rid of accepting subbmisions on forks, or design some better
// mechanism to deal with that case
if !rawSubmission.InOneBlock() && submissionState == OnFork {
onTheSameFork, err := m.onTheSameFork(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While on other methods we treat the number of submissions as variable (e.g. the GetSubmissionBtcState function), here we consider that there are two of those. Maybe we can abstract this inside the onTheSameFork function and just pass rawSubmission as an argument.

Copy link
Contributor

@gitferry gitferry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring! Left some small comments.

)

const (
Submitted SubmissionBtcState = iota
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would SubmissionBtcStatus be a better name? Just to be consistent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure 👍

// is implicit.
// TODO: Either get rid of accepting subbmisions on forks, or design some better
// mechanism to deal with that case
if !rawSubmission.InOneBlock() && submissionState == OnFork {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they are in one block, which is OnFork, why not reject the submission?

Copy link
Collaborator Author

@KonradStaniec KonradStaniec Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it can in principle end up in main chain.

My position in general is that we should not accept submission on forks at all (https://babylon-chain.atlassian.net/wiki/spaces/BABYLON/pages/34504933/ADR-001+Checkpoint+submission+acceptance+rules) and in general get rid of them as soon as possible (I think I am still waiting on @fishermanymc input on this)

If this propsal will be accepted I will make another pr which will further simplify a lot of logic here.

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates!

@KonradStaniec KonradStaniec merged commit ae35adf into main Oct 18, 2022
@KonradStaniec KonradStaniec deleted the simplify-handling-of-btc-status branch October 18, 2022 09:42
vitsalis pushed a commit that referenced this pull request Jan 21, 2024
maurolacy added a commit that referenced this pull request Jan 22, 2024
* Update babylon-contract

* Update README

* Fix localnet nodes 3 & 4

* Fix babylon contract instantiation

* Fix / adapt contract execution test

* Contract download script (#155)

Add download contract from release script

* Fix typos

* Reduce network / IB relayer start wait time

* Move IBC config to chain config

* Add BTC Timestamping Phase 2 test

* Improve syntax

Co-authored-by: Runchao Han <[email protected]>

* Revert "Fix localnet nodes 3 & 4"

This reverts commit aaf3707b28985d5f03261107d0fad518fc478527.

* Now fix localnet nodes 3 & 4

* Simplify phase-2 vs phase-1 test setup

* Simplify phase 2 test

* Make chain-B the CZ chain

* Use regtest const for network

* Use default checkpoint tag const for babylon tag

Update contract to custom

* Fix comment

Co-authored-by: Runchao Han <[email protected]>

* Update contract to custom

* Fix original test as well

* Increase delay to wait for chain ready

* Add (failing) next IBC packet sequence check

* Fix: contains wasm check

* Storage contract e2e (#171)

* Revert "Update babylon-contract"

This reverts commit 7c656b183818098f2662ac9996cde80b8f4009ba.

* Update storage-contract to custom

* Revert "Update README"

This reverts commit 3669c88d16b2ea1c8185ed53a74be0a0ae3b11ea.

* Revert "Fix babylon contract instantiation"

This reverts commit 1fb44d7fcfac3d79a4c8b9323a56eb8b0a837d83.

* Revert "Fix / adapt contract execution test"

This reverts commit 124099dd64dd519aba0774d3e5a7e43d7a44162a.

* Fix imports

* fix phase-2 e2e test (#163)

* Upgrade keyring / go-keychain dependency (#170)

* Add cosmos relayer docker image build

* Reduce cosmos-relayer image

* Set / use relayer tag

* Improve hermes bootstrap script

* Set ABCI packet persistence

* Add Cosmos relayer setup

* Enable debug logs

* Reduce relayer setup wait time

* Simplify seup / remove commented lines

* fix

* Fix: packet acknowledgements check

* Rename for consistency

* Same acknowledgements logic for Hermes relayer

* More test renaming for consistency

* Skip BTC timestamping phase 2 test (Hermes)

* Fix: BTC timestamping phase 1 tests

* Improve flaky BTC timestamping tests

* Return network to RegTest

* Update contracts code to latest

* Remove docker Platform directive / commented code

* Increase wait for blocks delay

* Add cosmos relayer docker build target to e2e target deps

* Fix rebase errors

* Remove unused helper

* Add TODOs

* Remove commented code

* Comment BTC timestamping hermes test out

* Restore original BTC timestamping test

* Report target arch / Go lang version

* Hardcode target arch for CI

* Hardcode next expected sequence

---------

Co-authored-by: Runchao Han <[email protected]>
Co-authored-by: Mauro Lacy <[email protected]>
maurolacy added a commit that referenced this pull request Jan 22, 2024
* Update babylon-contract

* Update README

* Fix localnet nodes 3 & 4

* Fix babylon contract instantiation

* Fix / adapt contract execution test

* Contract download script (#155)

Add download contract from release script

* Fix typos

* Reduce network / IB relayer start wait time

* Move IBC config to chain config

* Add BTC Timestamping Phase 2 test

* Improve syntax

Co-authored-by: Runchao Han <[email protected]>

* Revert "Fix localnet nodes 3 & 4"

This reverts commit aaf3707b28985d5f03261107d0fad518fc478527.

* Now fix localnet nodes 3 & 4

* Simplify phase-2 vs phase-1 test setup

* Simplify phase 2 test

* Make chain-B the CZ chain

* Use regtest const for network

* Use default checkpoint tag const for babylon tag

Update contract to custom

* Fix comment

Co-authored-by: Runchao Han <[email protected]>

* Update contract to custom

* Fix original test as well

* Increase delay to wait for chain ready

* Add (failing) next IBC packet sequence check

* Fix: contains wasm check

* Storage contract e2e (#171)

* Revert "Update babylon-contract"

This reverts commit 7c656b183818098f2662ac9996cde80b8f4009ba.

* Update storage-contract to custom

* Revert "Update README"

This reverts commit 3669c88d16b2ea1c8185ed53a74be0a0ae3b11ea.

* Revert "Fix babylon contract instantiation"

This reverts commit 1fb44d7fcfac3d79a4c8b9323a56eb8b0a837d83.

* Revert "Fix / adapt contract execution test"

This reverts commit 124099dd64dd519aba0774d3e5a7e43d7a44162a.

* Fix imports

* fix phase-2 e2e test (#163)

* Upgrade keyring / go-keychain dependency (#170)

* Add cosmos relayer docker image build

* Reduce cosmos-relayer image

* Set / use relayer tag

* Improve hermes bootstrap script

* Set ABCI packet persistence

* Add Cosmos relayer setup

* Enable debug logs

* Reduce relayer setup wait time

* Simplify seup / remove commented lines

* fix

* Fix: packet acknowledgements check

* Rename for consistency

* Same acknowledgements logic for Hermes relayer

* More test renaming for consistency

* Skip BTC timestamping phase 2 test (Hermes)

* Fix: BTC timestamping phase 1 tests

* Improve flaky BTC timestamping tests

* Return network to RegTest

* Update contracts code to latest

* Remove docker Platform directive / commented code

* Increase wait for blocks delay

* Add cosmos relayer docker build target to e2e target deps

* Fix rebase errors

* Remove unused helper

* Add TODOs

* Remove commented code

* Comment BTC timestamping hermes test out

* Restore original BTC timestamping test

* Report target arch / Go lang version

* Hardcode target arch for CI

* Hardcode next expected sequence

---------

Co-authored-by: Runchao Han <[email protected]>
Co-authored-by: Mauro Lacy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants