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

feat: e2e upgrade btc headers #4

Merged
merged 99 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
6165490
chore: add e2e software upgrade
RafilxTenfen Jul 29, 2024
61cfcaa
chore: only add upgrade if build with e2e tag
RafilxTenfen Jul 29, 2024
c36b17d
feat: add launch upgrade
RafilxTenfen Jul 30, 2024
3a40a02
chore: move name to launch signet
RafilxTenfen Jul 30, 2024
5b01140
fix: import cycle
RafilxTenfen Jul 30, 2024
85e0275
chore: moved pkg name to signerlaunch
RafilxTenfen Jul 30, 2024
c27b89e
fix: lint, panic if propLaunch fails
RafilxTenfen Jul 30, 2024
02a4b51
fixme: failing upgrade due to btc headers json not found
RafilxTenfen Jul 30, 2024
4165173
chore: update to use v09 before upgrade
RafilxTenfen Jul 30, 2024
ec9e59e
chore: removed fetch origin
RafilxTenfen Jul 30, 2024
6785106
fix: fetch all
RafilxTenfen Jul 30, 2024
d1775a9
chore: add identifier name to networks
RafilxTenfen Jul 30, 2024
34252d0
Merge branch 'rafilx/e2e-upgrade' of github.com:babylonlabs-io/babylo…
RafilxTenfen Jul 30, 2024
3d58d6d
chore: moved new btc headers to str instead of json
RafilxTenfen Jul 30, 2024
ef16043
Merge branch 'dev' of github.com:babylonlabs-io/babylon into rafilx/e…
RafilxTenfen Jul 30, 2024
6f92d84
chore: update vanilla file name and check the values are equal in btc…
RafilxTenfen Jul 30, 2024
4e115b4
fix: comparison with inserted values
RafilxTenfen Jul 30, 2024
a8cbda5
fix: compare the response of btc headers
RafilxTenfen Jul 30, 2024
7fdc39e
fix: reverse from chain stored
RafilxTenfen Jul 30, 2024
f81da6a
fix: reverse index read from chain stored
RafilxTenfen Jul 30, 2024
a56f499
fix: run migrations before prop updates
RafilxTenfen Aug 1, 2024
801ac1f
chore: rollback licence babylon labs
RafilxTenfen Aug 1, 2024
3c9ae61
fix: make sure the headers form a correct chain of btc blocks in the …
RafilxTenfen Aug 1, 2024
4cae2df
chore: add option to start with specific headers in e2e test init cha…
RafilxTenfen Aug 2, 2024
e10c032
chore: update to use only btc header bytes to upgrade
RafilxTenfen Aug 2, 2024
8dd3deb
chore: increase timeout of e2e test to 30m
RafilxTenfen Aug 2, 2024
199d0dc
chore: add check for cases where btc headers are not needed to specify
RafilxTenfen Aug 2, 2024
0b50fe6
fix: use identifier for networks
RafilxTenfen Aug 2, 2024
2500087
chore: free disk space
RafilxTenfen Aug 2, 2024
d1ef810
chore: turn back to e2e testing
RafilxTenfen Aug 2, 2024
73c7585
chore: add free disk space as need
RafilxTenfen Aug 2, 2024
6083067
chore: remove free disk space
RafilxTenfen Aug 2, 2024
6c3a898
chore: insert headers without trigger hook and events
RafilxTenfen Aug 5, 2024
b8a4ea5
chore: remove command that was removing docker images before build
RafilxTenfen Aug 5, 2024
853952a
chore: free disk sapce before run
RafilxTenfen Aug 5, 2024
7b5908f
chore: remove free disk space
RafilxTenfen Aug 5, 2024
bd9263d
chore: wait for clear resources before remove all the directories
RafilxTenfen Aug 5, 2024
c3de831
chore: refactory insert of headers to avoid bool parameter
RafilxTenfen Aug 5, 2024
3c5e4f3
Merge branch 'dev' of github.com:babylonlabs-io/babylon into rafilx/e…
RafilxTenfen Aug 6, 2024
89da374
chore: add diskfree
RafilxTenfen Aug 6, 2024
37cd9b6
Merge branch 'dev' of github.com:babylonlabs-io/babylon into rafilx/e…
RafilxTenfen Aug 6, 2024
42a5424
chore: remove free disk space
RafilxTenfen Aug 6, 2024
07398de
chore: add free disk space
RafilxTenfen Aug 6, 2024
5bc73d2
chore: add free disk
RafilxTenfen Aug 6, 2024
e090d22
fix: 60m test-e2e
RafilxTenfen Aug 7, 2024
be7fddc
chore: disable docker pipeline
RafilxTenfen Aug 7, 2024
4185fcc
chore: remove template
RafilxTenfen Aug 7, 2024
71b4a96
chore: add needs to lint as well
RafilxTenfen Aug 7, 2024
9e7893e
chore: remove free-disk
RafilxTenfen Aug 7, 2024
7c2de61
fix: make mocks lint
RafilxTenfen Aug 7, 2024
3407f71
chore: add comment for needs
RafilxTenfen Aug 7, 2024
ea74d03
chore: reduce the dockerfile size by only fetch the needed tag
RafilxTenfen Aug 7, 2024
30b9fd4
fix: fetch tag of docker
RafilxTenfen Aug 7, 2024
f2a641b
fix: docker build tag
RafilxTenfen Aug 7, 2024
36546a9
chore: add freespace :/
RafilxTenfen Aug 7, 2024
43efd95
chore: reduce dowload of go mods
RafilxTenfen Aug 7, 2024
a647f8b
chore: simplify identifier name
RafilxTenfen Aug 7, 2024
bf79895
chore: inital parallel
RafilxTenfen Aug 7, 2024
6dfb5d3
chore: disk space free
RafilxTenfen Aug 7, 2024
4f056d3
chore: avoid template and reuse dockers
RafilxTenfen Aug 7, 2024
d501d5a
fix: add concurrency to stop older actions run
RafilxTenfen Aug 7, 2024
7eea9bc
fix: add docker-login
RafilxTenfen Aug 7, 2024
c9f9fe9
fix: add docker-login to run
RafilxTenfen Aug 7, 2024
6add643
Merge branch 'rafilx/e2e-improve' of github.com:babylonlabs-io/babylo…
RafilxTenfen Aug 7, 2024
d920983
chore: use identifier in container naming
RafilxTenfen Aug 7, 2024
5bbdd60
tryfix: build and run e2e
RafilxTenfen Aug 7, 2024
5a034d2
chore: add artifacts to run TestBTCTimestampingTestSuite separate
RafilxTenfen Aug 8, 2024
bbcfebf
chore: add need for unit test
RafilxTenfen Aug 8, 2024
b4c03b1
tryfix: add e2e-run-upgrade-vanilla
RafilxTenfen Aug 8, 2024
3e7695d
tryfix: docker load to /tmp
RafilxTenfen Aug 8, 2024
b2207a5
chore: add check if artifact exists
RafilxTenfen Aug 8, 2024
d4c4122
fix: e2e init chain
RafilxTenfen Aug 8, 2024
29dadd7
feat: add run of test-e2e-cache-btc-timestamping-phase-2-hermes
RafilxTenfen Aug 8, 2024
1d49c9a
chore: add run for e2e btc staking
RafilxTenfen Aug 8, 2024
fa287f2
chore: update go cache name
RafilxTenfen Aug 8, 2024
7fcfcbf
chore: remove upgrade e2e signet launch
RafilxTenfen Aug 8, 2024
1a54e90
chore: remove sudo from make test-e2e-cache-btc-timestamping
RafilxTenfen Aug 8, 2024
36d6584
fix: remove sudo to use cache from golang
RafilxTenfen Aug 8, 2024
017aced
chore: remove require no error on clear resources due to unlinkat /tm…
RafilxTenfen Aug 8, 2024
314ea08
Merge branch 'rafilx/e2e-improve-parallel' of github.com:babylonlabs-…
RafilxTenfen Aug 8, 2024
59eb0d7
chore: add identifier for each run
RafilxTenfen Aug 8, 2024
f34b3d3
chore: remove unecessary multistage parts
RafilxTenfen Aug 8, 2024
1d56154
Merge branch 'rafilx/e2e-improve' of github.com:babylonlabs-io/babylo…
RafilxTenfen Aug 8, 2024
8e8db82
chore: add logs for it
RafilxTenfen Aug 8, 2024
cc9c786
chore: cap identifier size
RafilxTenfen Aug 8, 2024
0ccb5f5
chore: remove artifact checker
RafilxTenfen Aug 8, 2024
7ff9ab3
chore: add logs to debug e2e upgrade
RafilxTenfen Aug 8, 2024
9afdd95
fix: use babylond with e2e tag for all e2e testing
RafilxTenfen Aug 8, 2024
e104607
chore: add ci template back for all cases except e2e test
RafilxTenfen Aug 8, 2024
2f7e46c
chore: remove debug comments and rollback to use network id
RafilxTenfen Aug 8, 2024
7b850aa
chore: update directive of dockerfile
RafilxTenfen Aug 8, 2024
9b3da6c
Merge branch 'rafilx/e2e-improve-docker-cache' of github.com:babylonl…
RafilxTenfen Aug 8, 2024
a2a76fe
chore: remove debug logs
RafilxTenfen Aug 8, 2024
67683f3
Merge branch 'rafilx/e2e-improve-docker-cache' of github.com:babylonl…
RafilxTenfen Aug 8, 2024
e6cbb29
chore: add run of signet test
RafilxTenfen Aug 8, 2024
0a79c38
Merge branch 'dev' of github.com:babylonlabs-io/babylon into rafilx/e…
RafilxTenfen Aug 9, 2024
2987907
chore: removed e2e test run on publish ci
RafilxTenfen Aug 9, 2024
6a4027d
chore: rename headerZero to headerGenesis
RafilxTenfen Aug 9, 2024
628c1a6
chore: fix concurrent map write
RafilxTenfen Aug 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,45 @@ jobs:
go-version: 1.21
- name: Run e2e TestSoftwareUpgradeTestSuite
run: |
sudo make test-e2e-cache-upgrade-vanilla
sudo make test-e2e-cache-upgrade-vanilla

e2e-run-upgrade-signet:
needs: [e2e-docker-build-babylon, e2e-docker-build-babylon-before-upgrade, e2e-docker-build-e2e-init-chain]
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download babylon artifact
uses: actions/download-artifact@v4
with:
name: babylond-${{ github.sha }}
path: /tmp
- name: Download babylond-before-upgrade artifact
uses: actions/download-artifact@v4
with:
name: babylond-before-upgrade
path: /tmp
- name: Download init-chain artifact
uses: actions/download-artifact@v4
with:
name: init-chain
path: /tmp
- name: Docker load babylond
run: |
docker load < /tmp/docker-babylond.tar.gz

- name: Docker load babylond-before-upgrade
run: |
docker load < /tmp/docker-babylond-before-upgrade.tar.gz

- name: Docker load init chain
run: |
docker load < /tmp/docker-init-chain.tar.gz

- name: Cache Go
uses: actions/setup-go@v5
with:
go-version: 1.21
- name: Run e2e TestSoftwareUpgradeSignetLaunchTestSuite
run: |
sudo make test-e2e-cache-upgrade-signet
4 changes: 1 addition & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ jobs:
uses: babylonlabs-io/.github/.github/workflows/[email protected]
with:
run-unit-tests: true
run-integration-tests: true
run-integration-tests: false
run-lint: true
integration-tests-command: |
sudo make test-e2e

docker_pipeline:
uses: babylonlabs-io/.github/.github/workflows/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ test-e2e-cache-btc-staking:
test-e2e-cache-upgrade-vanilla:
go test -run TestSoftwareUpgradeTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-upgrade-signet:
go test -run TestSoftwareUpgradeSignetLaunchTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-sim-nondeterminism:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
Expand Down
7 changes: 5 additions & 2 deletions app/e2e_include_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

package app

import "github.com/babylonlabs-io/babylon/app/upgrades/vanilla"
import (
"github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch"
"github.com/babylonlabs-io/babylon/app/upgrades/vanilla"
)

func init() {
Upgrades = append(Upgrades, vanilla.Upgrade)
Upgrades = append(Upgrades, vanilla.Upgrade, signetlaunch.Upgrade)
}
22 changes: 22 additions & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"bytes"
"encoding/json"
"os"
"testing"
Expand All @@ -15,6 +16,7 @@ import (
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cosmosed "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
Expand All @@ -35,6 +37,7 @@ import (
"github.com/babylonlabs-io/babylon/crypto/bls12381"
"github.com/babylonlabs-io/babylon/privval"
bbn "github.com/babylonlabs-io/babylon/types"
btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
checkpointingtypes "github.com/babylonlabs-io/babylon/x/checkpointing/types"
)

Expand Down Expand Up @@ -354,3 +357,22 @@ func initAccountWithCoins(app *BabylonApp, ctx sdk.Context, addr sdk.AccAddress,
panic(err)
}
}

// SignetBtcHeaderGenesis returns the BTC Header block zero from signet.
func SignetBtcHeaderGenesis(cdc codec.Codec) (*btclighttypes.BTCHeaderInfo, error) {
var btcHeaderGenesis btclighttypes.BTCHeaderInfo
// signet btc header 0
btcHeaderGenesisStr := `{
"header": "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a008f4d5fae77031e8ad22203",
"hash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6",
"work": "77414720"
}`
buff := bytes.NewBufferString(btcHeaderGenesisStr)

err := cdc.UnmarshalJSON(buff.Bytes(), &btcHeaderGenesis)
if err != nil {
return nil, err
}

return &btcHeaderGenesis, nil
}
4 changes: 4 additions & 0 deletions app/upgrades/signetlaunch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Signet Launch

This folder contains a software upgrade for testing purposes.
DO NOT USE IN PRODUCTION!
51 changes: 51 additions & 0 deletions app/upgrades/signetlaunch/data_btc_headers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package signetlaunch

const NewBtcHeadersStr = `{
"btc_headers": [
{
"header": "00000020f61eee3b63a380a477a063af32b2bbc97c9ff9f01f2c4225e973988108000000f575c83235984e7dc4afc1f30944c170462e84437ab6f2d52e16878a79e4678bd1914d5fae77031eccf40700"
},
{
"header": "00000020533b53ded9bff4adc94101d32400a144c54edc5ed492a3b26c63b2d686000000b38fef50592017cfafbcab88eb3d9cf50b2c801711cad8299495d26df5e54812e7914d5fae77031ecfdd0b00"
},
{
"header": "000000202960f3752f0bfa8858a3e333294aedc7808025e868c9dc03e71d88bb320000007765fcd3d5b4966beb338bba2675dc2cf2ad28d4ad1d83bdb6f286e7e27ac1f807924d5fae77031e81d60b00"
},
{
"header": "00000020b06443a13ae1d3d50faef5ecad38c6818194dc46abca3e972e2aacdae800000069a5829097e80fee00ac49a56ea9f82d741a6af84d32b3bc455cf31871e2a8ac27924d5fae77031e9c910500"
},
{
"header": "000000207ed403758a4f228a1939418a155e2ebd4ae6b26e5ffd0ae433123f7694010000542e80b609c5bc58af5bdf492e26d4f60cd43a3966c2e063c50444c29b3757a636924d5fae77031ee8601d00"
},
{
"header": "000000205bea0a88d1422c3df08d766ad72df95084d0700e6f873b75dd4e986c7703000002b57516d33ed60c2bdd9f93d6d5614083324c837e68e5ba6e04287a7285633585924d5fae77031ed1719600"
},
{
"header": "00000020daf3b60d374b19476461f97540498dcfa2eb7016238ec6b1d022f82fb60100007a7ae65b53cb988c2ec92d2384996713821d5645ffe61c9acea60da75cd5edfa1a944d5fae77031e9dbb0500"
},
{
"header": "00000020457cc5f3c2e1a5655bc20e20e48d33e1b7ea68786c614032b5c518f0b6000000541f36942d82c6e7248275ff15c8933487fbe1819c67a9ecc0f4b70bb7e6cf672a944d5fae77031e8f398600"
},
{
"header": "00000020a2eb61eb4f3831baa3a3363e1b42db4462663f756f07423e81ed30322102000077224de7dea0f8d0ec22b1d2e2e255f0a987b96fe7200e1a2e6373f48a2f5b7894954d5fae77031e36867e00"
},
{
"header": "00000020a868e8514be5e46dabd6a122132f423f36a43b716a40c394e2a8d063e1010000f4c6c717e99d800c699c25a2006a75a0c5c09f432a936f385e6fce139cdbd1a5e9964d5fae77031e7d026e00"
},
{
"header": "000000205b969d72d19a47f39703c89a0cdb9eada8c4db934064f30e31f89a8e41010000949eef89068ffc76bf4dca6762e26581d410d0df40edf147d4ffdc6dea404a1512984d5fae77031ee67c1200"
},
{
"header": "000000209410d824b5c57e762922a4035d300bd1d24db4e57b130ff7762ae5df4c030000532299955b2dc6bd7c13c267d3c0990fefdf7aec3bcbab5b2c85d0d36316f93644984d5fae77031ecdea1600"
},
{
"header": "0000002009f649453a4079cb1d1beb138ea915d2355788bd4689785ecf7a265d3700000010bd26b43a88350e614736674431e62cc7c77dc577d07edd80620a02339d5fab82984d5fae77031efe682400"
},
{
"header": "0000002035b9ff9157a6e7b5b9ee3807b8246ab687d2ee340f5b0f86cd0e2798aa00000028ef48260b3c0d45bbe5321335b05dde8fcb130e063202457884585298b8a5dde4984d5fae77031ec0a08600"
},
{
"header": "0000002086102ffb6fd14131a08faa1e87680d5470954ba9638f15b56b7345de500100009f423c63aa6d39330082b58808013a85af5a7f338a7a3587f0a85b587665e6174e9a4d5fae77031e79353a00"
}
]
}`
107 changes: 107 additions & 0 deletions app/upgrades/signetlaunch/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// This code is only for testing purposes.
// DO NOT USE IN PRODUCTION!

package signetlaunch

import (
"bytes"
"context"
"errors"
"fmt"

store "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/btcsuite/btcd/chaincfg"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/babylonlabs-io/babylon/app/keepers"
appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/app/upgrades"
bbn "github.com/babylonlabs-io/babylon/types"
btclightkeeper "github.com/babylonlabs-io/babylon/x/btclightclient/keeper"
btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: "signet-launch",
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}

// CreateUpgradeHandler upgrade handler for launch.
func CreateUpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
app upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(context context.Context, _plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(context)

migrations, err := mm.RunMigrations(ctx, cfg, fromVM)
if err != nil {
return nil, err
}

if err := propLaunch(ctx, &keepers.BTCLightClientKeeper); err != nil {
panic(err)
}

return migrations, nil
}
}

// propLaunch runs the proposal of launch that is meant to insert new BTC Headers.
func propLaunch(
ctx sdk.Context,
btcLigthK *btclightkeeper.Keeper,
) error {
newHeaders, err := LoadBTCHeadersFromData()
if err != nil {
return err
}

return insertBtcHeaders(ctx, btcLigthK, newHeaders)
}

// LoadBTCHeadersFromData returns the BTC headers load from the json string with the headers inside of it.
func LoadBTCHeadersFromData() ([]*btclighttypes.BTCHeaderInfo, error) {
cdc := appparams.DefaultEncodingConfig().Codec
buff := bytes.NewBufferString(NewBtcHeadersStr)

var gs btclighttypes.GenesisState
err := cdc.UnmarshalJSON(buff.Bytes(), &gs)
if err != nil {
return nil, err
}

return gs.BtcHeaders, nil
}

func insertBtcHeaders(
ctx sdk.Context,
k *btclightkeeper.Keeper,
btcHeaders []*btclighttypes.BTCHeaderInfo,
) error {
if len(btcHeaders) == 0 {
return errors.New("no headers to insert")
}

headersBytes := make([]bbn.BTCHeaderBytes, len(btcHeaders))
for i, btcHeader := range btcHeaders {
h := btcHeader
headersBytes[i] = *h.Header
}

if err := k.InsertHeaders(ctx, headersBytes); err != nil {
RafilxTenfen marked this conversation as resolved.
Show resolved Hide resolved
return err
}

allBlocks := k.GetMainChainFromWithLimit(ctx, 0, 1)
isRetarget := btclighttypes.IsRetargetBlock(allBlocks[0], &chaincfg.SigNetParams)
if !isRetarget {
return fmt.Errorf("first header be a difficulty adjustment block")
}
return nil
}
Loading
Loading