From 61654901e525d37d42da2c2c455aa9e2d8830ede Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 29 Jul 2024 13:20:43 -0300 Subject: [PATCH 01/89] chore: add e2e software upgrade --- Makefile | 23 +- app/app.go | 7 +- app/upgrades/vanilla/upgrades.go | 41 ++- contrib/images/Makefile | 18 +- contrib/images/babylond/Dockerfile | 5 +- .../images/e2e-initialization/init.Dockerfile | 43 +++ test/e2e/btc_staking_e2e_test.go | 16 +- test/e2e/configurer/base.go | 17 +- test/e2e/configurer/chain/chain.go | 11 +- test/e2e/configurer/chain/commands.go | 59 ++++ test/e2e/configurer/chain/node.go | 17 ++ test/e2e/configurer/chain/queries.go | 53 ++++ test/e2e/configurer/config/constants.go | 10 + test/e2e/configurer/factory.go | 29 +- test/e2e/configurer/setup.go | 28 +- test/e2e/configurer/upgrade.go | 269 ++++++++++++++++++ test/e2e/containers/config.go | 37 ++- test/e2e/containers/containers.go | 58 +++- test/e2e/e2e_test.go | 5 + test/e2e/ibc_transfer_e2e_test.go | 4 +- test/e2e/initialization/config.go | 23 +- test/e2e/initialization/export.go | 3 - test/e2e/initialization/node.go | 1 - test/e2e/software_upgrade_e2e_test.go | 50 ++++ test/e2e/upgrades/vanilla.json | 14 + wasmbinding/testdata/README.md | 1 - 26 files changed, 771 insertions(+), 71 deletions(-) create mode 100644 contrib/images/e2e-initialization/init.Dockerfile create mode 100644 test/e2e/configurer/upgrade.go create mode 100644 test/e2e/software_upgrade_e2e_test.go create mode 100644 test/e2e/upgrades/vanilla.json diff --git a/Makefile b/Makefile index 4c8db9052..aadf3bde4 100644 --- a/Makefile +++ b/Makefile @@ -204,6 +204,17 @@ build-docs: diagrams ## Builds a docs site done < versions ; .PHONY: build-docs +############################################################################### +### E2E build ### +############################################################################### + +# Executed to build the binary for chain initialization, one of +## chain => test/e2e/initialization/chain/main.go +## node => test/e2e/initialization/node/main.go +e2e-build-script: + mkdir -p $(BUILDDIR) + go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./test/e2e/initialization/$(E2E_SCRIPT_NAME) + ############################################################################### ### Tests & Simulation ### ############################################################################### @@ -243,7 +254,7 @@ endif .PHONY: run-tests test test-all $(TEST_TARGETS) -test-e2e: build-docker +test-e2e: build-docker-e2e go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -count=1 --tags=e2e test-sim-nondeterminism: @@ -411,14 +422,22 @@ proto-lint: ## Lint protobuf files ############################################################################### ### Docker ### ############################################################################### +dockerNetworkList=$($(DOCKER) network ls --filter name=bbn-testnet --format {{.ID}}) build-docker: ## Build babylond Docker image $(MAKE) -C contrib/images babylond +build-docker-e2e: build-docker + $(MAKE) -C contrib/images babylond-before-upgrade + $(MAKE) -C contrib/images e2e-init-chain + build-cosmos-relayer-docker: ## Build Docker image for the Cosmos relayer $(MAKE) -C contrib/images cosmos-relayer -.PHONY: build-docker build-cosmos-relayer-docker +clean-docker-network: + $(DOCKER) network rm ${dockerNetworkList} + +.PHONY: build-docker build-docker-e2e build-cosmos-relayer-docker clean-docker-network ############################################################################### ### Localnet ### diff --git a/app/app.go b/app/app.go index 541bcd8d3..4e019d25c 100644 --- a/app/app.go +++ b/app/app.go @@ -94,6 +94,7 @@ import ( "github.com/spf13/cast" "github.com/babylonlabs-io/babylon/app/upgrades" + "github.com/babylonlabs-io/babylon/app/upgrades/vanilla" bbn "github.com/babylonlabs-io/babylon/types" appkeepers "github.com/babylonlabs-io/babylon/app/keepers" @@ -158,8 +159,10 @@ var ( } // software upgrades and forks - Upgrades = []upgrades.Upgrade{} - Forks = []upgrades.Fork{} + Upgrades = []upgrades.Upgrade{ + vanilla.Upgrade, + } + Forks = []upgrades.Fork{} ) func init() { diff --git a/app/upgrades/vanilla/upgrades.go b/app/upgrades/vanilla/upgrades.go index 35d546958..cb01322e5 100644 --- a/app/upgrades/vanilla/upgrades.go +++ b/app/upgrades/vanilla/upgrades.go @@ -46,18 +46,47 @@ func propVanilla( accountKeeper *authkeeper.AccountKeeper, bsKeeper *btcstakingkeeper.Keeper, ) { - // remove an account + // remove the account with higher number and the lowest is the new fp addr allAccounts := accountKeeper.GetAllAccounts(ctx) - accountKeeper.RemoveAccount(ctx, allAccounts[len(allAccounts)-1]) + var ( + accToRemove sdk.AccountI + accFp sdk.AccountI + ) + heighestAccNumber, lowestAccNumber := uint64(0), uint64(len(allAccounts)) - // insert a FP - sk, err := btcec.NewPrivateKey() + for _, acc := range allAccounts { + accNumber := acc.GetAccountNumber() + if accNumber > heighestAccNumber { + heighestAccNumber = accNumber + accToRemove = acc + } + if accNumber < lowestAccNumber { + lowestAccNumber = accNumber + accFp = acc + } + } + + accountKeeper.RemoveAccount(ctx, accToRemove) + + // insert a FP from predefined public key + pk, err := btcec.ParsePubKey( + []byte{0x06, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, + 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, + 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, + 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a, + 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, + 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17, 0xb4, 0x48, + 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, + 0x10, 0xd4, 0xb8, + }, + ) if err != nil { panic(err) } - btcPK := bbn.NewBIP340PubKeyFromBTCPK(sk.PubKey()) + + btcPK := bbn.NewBIP340PubKeyFromBTCPK(pk) fp := &bstypes.FinalityProvider{ - Addr: allAccounts[0].GetAddress().String(), + Addr: accFp.GetAddress().String(), BtcPk: btcPK, } bsKeeper.SetFinalityProvider(ctx, fp) diff --git a/contrib/images/Makefile b/contrib/images/Makefile index 67e2fc470..214ebbe5a 100644 --- a/contrib/images/Makefile +++ b/contrib/images/Makefile @@ -1,20 +1,30 @@ RELAYER_TAG := $(shell grep '^ENV RELAYER_TAG' cosmos-relayer/Dockerfile | cut -f3 -d\ ) +BABYLON_FULL_PATH := $(shell git rev-parse --show-toplevel) +BABYLON_VERSION_BEFORE_UPGRADE ?= 5f8af8ced17d24f3f0c6172293cd37fb3d055807 all: babylond cosmos-relayer babylond: babylond-rmi - docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile \ - $(shell git rev-parse --show-toplevel) + docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile ${BABYLON_FULL_PATH} + +babylond-before-upgrade: + docker rmi babylonlabs-io/babylond-before-upgrade 2>/dev/null; true && \ + docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile \ + --build-arg VERSION="${BABYLON_VERSION_BEFORE_UPGRADE}" ${BABYLON_FULL_PATH} babylond-rmi: docker rmi babylonlabs-io/babylond 2>/dev/null; true +e2e-init-chain: + @DOCKER_BUILDKIT=1 docker build -t babylonlabs-io/babylond-e2e-init-chain --build-arg E2E_SCRIPT_NAME=chain --platform=linux/x86_64 \ + -f e2e-initialization/init.Dockerfile ${BABYLON_FULL_PATH} + cosmos-relayer: cosmos-relayer-rmi docker build --tag babylonlabs-io/cosmos-relayer:${RELAYER_TAG} -f cosmos-relayer/Dockerfile \ - $(shell git rev-parse --show-toplevel)/contrib/images/cosmos-relayer + ${BABYLON_FULL_PATH}/contrib/images/cosmos-relayer docker tag babylonlabs-io/cosmos-relayer:${RELAYER_TAG} babylonlabs-io/cosmos-relayer:latest cosmos-relayer-rmi: docker rmi babylonlabs-io/cosmos-relayer 2>/dev/null; true -.PHONY: all babylond cosmos-relayer babylond-rmi cosmos-relayer-rmi +.PHONY: all babylond babylond-before-upgrade cosmos-relayer e2e-init-chain babylond-rmi cosmos-relayer-rmi diff --git a/contrib/images/babylond/Dockerfile b/contrib/images/babylond/Dockerfile index d4e8957fb..76c315562 100644 --- a/contrib/images/babylond/Dockerfile +++ b/contrib/images/babylond/Dockerfile @@ -1,9 +1,5 @@ FROM golang:1.21 AS build-env -# Customize to your build env - -# TARGETPLATFORM should be one of linux/amd64 or linux/arm64. -ARG TARGETPLATFORM="linux/amd64" # Version to build. Default is empty ARG VERSION @@ -23,6 +19,7 @@ RUN go mod download COPY ./ /go/src/github.com/babylonlabs-io/babylon/ # If version is set, then checkout this version RUN if [ -n "${VERSION}" ]; then \ + git fetch origin ${VERSION}; \ git checkout -f ${VERSION}; \ fi diff --git a/contrib/images/e2e-initialization/init.Dockerfile b/contrib/images/e2e-initialization/init.Dockerfile new file mode 100644 index 000000000..f457829ed --- /dev/null +++ b/contrib/images/e2e-initialization/init.Dockerfile @@ -0,0 +1,43 @@ +FROM golang:1.21 as build-env + +ARG E2E_SCRIPT_NAME + +# Install cli tools for building and final image +RUN apt-get update && apt-get install -y make git bash gcc curl jq + +WORKDIR /go/src/github.com/babylonlabs-io/babylon + +# First cache dependencies +COPY go.mod go.sum /go/src/github.com/babylonlabs-io/babylon/ +RUN go mod download + +# Copy everything else +COPY ./ /go/src/github.com/babylonlabs-io/babylon/ + +RUN LEDGER_ENABLED=false LINK_STATICALLY=false E2E_SCRIPT_NAME=${E2E_SCRIPT_NAME} make e2e-build-script + +FROM debian:bookworm-slim AS run + +# Create a user +RUN addgroup --gid 1137 --system babylon && adduser --uid 1137 --gid 1137 --system --home /home/babylon babylon +RUN apt-get update && apt-get install -y bash curl jq wget + +COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/go.mod /tmp +RUN WASMVM_VERSION=$(grep github.com/CosmWasm/wasmvm /tmp/go.mod | cut -d' ' -f2) && \ + wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.$(uname -m).so \ + -O /lib/libwasmvm.$(uname -m).so && \ + # verify checksum + wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \ + sha256sum /lib/libwasmvm.$(uname -m).so | grep $(cat /tmp/checksums.txt | grep libwasmvm.$(uname -m) | cut -d ' ' -f 1) + +# Args only last for a single build stage - renew +ARG E2E_SCRIPT_NAME + +COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/build/${E2E_SCRIPT_NAME} /bin/${E2E_SCRIPT_NAME} + +# Docker ARGs are not expanded in ENTRYPOINT in the exec mode. At the same time, +# it is impossible to add CMD arguments when running a container in the shell mode. +# As a workaround, we create the entrypoint.sh script to bypass these issues. +RUN echo "#!/bin/bash\n${E2E_SCRIPT_NAME} \"\$@\"" >> entrypoint.sh && chmod +x entrypoint.sh + +ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/test/e2e/btc_staking_e2e_test.go b/test/e2e/btc_staking_e2e_test.go index d4bcf2775..05c97395e 100644 --- a/test/e2e/btc_staking_e2e_test.go +++ b/test/e2e/btc_staking_e2e_test.go @@ -297,12 +297,12 @@ func (s *BTCStakingTestSuite) Test3CommitPublicRandomnessAndSubmitFinalitySignat s.Equal(prCommitMap[activatedHeight].Commitment, msgCommitPubRandList.Commitment) // no reward gauge for finality provider and delegation yet - fpBabylonAddr := sdk.AccAddress(nonValidatorNode.SecretKey.PubKey().Address().Bytes()) + fpBabylonAddr, err := sdk.AccAddressFromBech32(cacheFP.Addr) + s.NoError(err) + _, err = nonValidatorNode.QueryRewardGauge(fpBabylonAddr) - s.Error(err) - delBabylonAddr := sdk.AccAddress(nonValidatorNode.SecretKey.PubKey().Address().Bytes()) - _, err = nonValidatorNode.QueryRewardGauge(delBabylonAddr) - s.Error(err) + s.ErrorContains(err, itypes.ErrRewardGaugeNotFound.Error()) + delBabylonAddr := fpBabylonAddr /* submit finality signature @@ -358,8 +358,10 @@ func (s *BTCStakingTestSuite) Test4WithdrawReward() { s.NoError(err) // finality provider balance before withdraw - fpBabylonAddr := sdk.AccAddress(nonValidatorNode.SecretKey.PubKey().Address().Bytes()) - delBabylonAddr := sdk.AccAddress(nonValidatorNode.SecretKey.PubKey().Address().Bytes()) + fpBabylonAddr, err := sdk.AccAddressFromBech32(cacheFP.Addr) + s.NoError(err) + delBabylonAddr := fpBabylonAddr + fpBalance, err := nonValidatorNode.QueryBalances(fpBabylonAddr.String()) s.NoError(err) // finality provider reward gauge should not be fully withdrawn diff --git a/test/e2e/configurer/base.go b/test/e2e/configurer/base.go index 302fd8ca9..de34baa2e 100644 --- a/test/e2e/configurer/base.go +++ b/test/e2e/configurer/base.go @@ -19,6 +19,7 @@ import ( "github.com/babylonlabs-io/babylon/types" types2 "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" "github.com/stretchr/testify/require" + "golang.org/x/sync/errgroup" ) // baseConfigurer is the base implementation for the @@ -39,16 +40,18 @@ const defaultSyncUntilHeight = 3 func (bc *baseConfigurer) ClearResources() error { bc.t.Log("tearing down e2e integration test suite...") - if err := bc.containerManager.ClearResources(); err != nil { - return err - } + g := new(errgroup.Group) + g.Go(func() error { + return bc.containerManager.ClearResources() + }) for _, chainConfig := range bc.chainConfigs { - if err := os.RemoveAll(chainConfig.DataDir); err != nil { - return err - } + chainConfig := chainConfig + g.Go(func() error { + return os.RemoveAll(chainConfig.DataDir) + }) } - return nil + return g.Wait() } func (bc *baseConfigurer) GetChainConfig(chainIndex int) *chain.Config { diff --git a/test/e2e/configurer/chain/chain.go b/test/e2e/configurer/chain/chain.go index a6d92dc3f..c0a5ef195 100644 --- a/test/e2e/configurer/chain/chain.go +++ b/test/e2e/configurer/chain/chain.go @@ -2,10 +2,12 @@ package chain import ( "fmt" - ibctesting "github.com/cosmos/ibc-go/v8/testing" "testing" "time" + govv1 "cosmossdk.io/api/cosmos/gov/v1" + ibctesting "github.com/cosmos/ibc-go/v8/testing" + coretypes "github.com/cometbft/cometbft/rpc/core/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -173,3 +175,10 @@ func (c *Config) GetNodeAtIndex(nodeIndex int) (*NodeConfig, error) { } return c.NodeConfigs[nodeIndex], nil } + +// TxGovVoteFromAllNodes votes in a gov prop from all nodes wallet. +func (c *Config) TxGovVoteFromAllNodes(propID int, option govv1.VoteOption, overallFlags ...string) { + for _, n := range c.NodeConfigs { + n.TxGovVote(n.WalletName, propID, option, overallFlags...) + } +} diff --git a/test/e2e/configurer/chain/commands.go b/test/e2e/configurer/chain/commands.go index 36155d45c..feca59645 100644 --- a/test/e2e/configurer/chain/commands.go +++ b/test/e2e/configurer/chain/commands.go @@ -12,6 +12,7 @@ import ( "strings" "time" + govv1 "cosmossdk.io/api/cosmos/gov/v1" txformat "github.com/babylonlabs-io/babylon/btctxformatter" "github.com/babylonlabs-io/babylon/test/e2e/containers" "github.com/babylonlabs-io/babylon/test/e2e/initialization" @@ -94,6 +95,10 @@ func (n *NodeConfig) BankSendFromNode(receiveAddress, amount string) { n.BankSend(n.WalletName, receiveAddress, amount) } +func (n *NodeConfig) BankMultiSendFromNode(addresses []string, amount string) { + n.BankMultiSend(n.WalletName, addresses, amount) +} + func (n *NodeConfig) BankSend(fromWallet, to, amount string, overallFlags ...string) { fromAddr := n.GetWallet(fromWallet) n.LogActionF("bank sending %s from wallet %s to %s", amount, fromWallet, to) @@ -103,6 +108,23 @@ func (n *NodeConfig) BankSend(fromWallet, to, amount string, overallFlags ...str n.LogActionF("successfully sent bank sent %s from address %s to %s", amount, fromWallet, to) } +func (n *NodeConfig) BankMultiSend(fromWallet string, receivers []string, amount string, overallFlags ...string) { + if len(receivers) == 0 { + require.Error(n.t, fmt.Errorf("no address to send to")) + } + + fromAddr := n.GetWallet(fromWallet) + n.LogActionF("bank multi-send sending %s from wallet %s to %+v", amount, fromWallet, receivers) + + cmd := []string{"babylond", "tx", "bank", "multi-send", fromAddr} // starts the initial flags + cmd = append(cmd, receivers...) // appends all the receivers + cmd = append(cmd, amount, fmt.Sprintf("--from=%s", fromWallet)) // set amounts and overall + + _, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, append(cmd, overallFlags...)) + require.NoError(n.t, err) + n.LogActionF("successfully sent bank multi-send %s from address %s to %+v", amount, fromWallet, receivers) +} + func (n *NodeConfig) BankSendOutput(fromWallet, to, amount string, overallFlags ...string) (out bytes.Buffer, errBuff bytes.Buffer, err error) { fromAddr := n.GetWallet(fromWallet) n.LogActionF("bank sending %s from wallet %s to %s", amount, fromWallet, to) @@ -385,3 +407,40 @@ func ParseBTCHeaderInfoResponseToInfo(r *blc.BTCHeaderInfoResponse) (*blc.BTCHea Work: &r.Work, }, nil } + +// Proposal submits a governance proposal from the file inside the container, +// if the file is local, remind to add it to the mounting point in container. +func (n *NodeConfig) TxGovPropSubmitProposal(proposalJsonFilePath, from string, overallFlags ...string) int { + n.LogActionF("submitting new v1 proposal type %s", proposalJsonFilePath) + + cmd := []string{ + "babylond", "tx", "gov", "submit-proposal", proposalJsonFilePath, + fmt.Sprintf("--from=%s", from), + } + + _, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, append(cmd, overallFlags...)) + require.NoError(n.t, err) + + n.WaitForNextBlock() + + props := n.QueryProposals() + require.GreaterOrEqual(n.t, len(props.Proposals), 1) + + n.LogActionF("successfully submitted new v1 proposal type") + return int(props.Proposals[len(props.Proposals)-1].ProposalId) +} + +// TxGovVote votes in a governance proposal +func (n *NodeConfig) TxGovVote(from string, propID int, option govv1.VoteOption, overallFlags ...string) { + n.LogActionF("submitting vote %s to prop %d", option, propID) + + cmd := []string{ + "babylond", "tx", "gov", "vote", fmt.Sprintf("%d", propID), option.String(), + fmt.Sprintf("--from=%s", from), + } + + _, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, append(cmd, overallFlags...)) + require.NoError(n.t, err) + + n.LogActionF("successfully submitted vote %s to prop %d", option, propID) +} diff --git a/test/e2e/configurer/chain/node.go b/test/e2e/configurer/chain/node.go index f849ac5ab..c07288c17 100644 --- a/test/e2e/configurer/chain/node.go +++ b/test/e2e/configurer/chain/node.go @@ -9,6 +9,7 @@ import ( "testing" "time" + cmtjson "github.com/cometbft/cometbft/libs/json" rpchttp "github.com/cometbft/cometbft/rpc/client/http" coretypes "github.com/cometbft/cometbft/rpc/core/types" "github.com/stretchr/testify/require" @@ -185,3 +186,19 @@ func (n *NodeConfig) LogActionF(msg string, args ...interface{}) { s := fmt.Sprintf(msg, args...) n.t.Logf("[%s] %s. From container %s", timeSinceStart, s, n.Name) } + +func (n *NodeConfig) Status() (*coretypes.ResultStatus, error) { + cmd := []string{"babylond", "status", "--output=json"} + outBuf, _, err := n.containerManager.ExecCmd(n.t, n.Name, cmd, "") + if err != nil { + return nil, err + } + + var r coretypes.ResultStatus + err = cmtjson.Unmarshal(outBuf.Bytes(), &r) + if err != nil { + return nil, err + } + + return &r, nil +} diff --git a/test/e2e/configurer/chain/queries.go b/test/e2e/configurer/chain/queries.go index ff4ae0302..178349bbf 100644 --- a/test/e2e/configurer/chain/queries.go +++ b/test/e2e/configurer/chain/queries.go @@ -12,6 +12,7 @@ import ( "time" sdkmath "cosmossdk.io/math" + upgradetypes "cosmossdk.io/x/upgrade/types" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" cmtabcitypes "github.com/cometbft/cometbft/abci/types" cmttypes "github.com/cometbft/cometbft/types" @@ -19,6 +20,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/query" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/stretchr/testify/require" "github.com/babylonlabs-io/babylon/test/e2e/util" @@ -413,3 +415,54 @@ func (n *NodeConfig) QueryWasmSmartObject(contract string, msg string) (resultOb } return resultObject, nil } + +func (n *NodeConfig) QueryProposal(proposalNumber int) govtypesv1.QueryProposalResponse { + path := fmt.Sprintf("cosmos/gov/v1beta1/proposals/%d", proposalNumber) + bz, err := n.QueryGRPCGateway(path, url.Values{}) + require.NoError(n.t, err) + + var resp govtypesv1.QueryProposalResponse + err = util.Cdc.UnmarshalJSON(bz, &resp) + require.NoError(n.t, err) + + return resp +} + +func (n *NodeConfig) QueryProposals() govtypesv1.QueryProposalsResponse { + bz, err := n.QueryGRPCGateway("cosmos/gov/v1beta1/proposals", url.Values{}) + require.NoError(n.t, err) + + var resp govtypesv1.QueryProposalsResponse + err = util.Cdc.UnmarshalJSON(bz, &resp) + require.NoError(n.t, err) + + return resp +} + +func (n *NodeConfig) QueryAppliedPlan(planName string) upgradetypes.QueryAppliedPlanResponse { + path := fmt.Sprintf("cosmos/upgrade/v1beta1/applied_plan/%s", planName) + bz, err := n.QueryGRPCGateway(path, url.Values{}) + require.NoError(n.t, err) + + var resp upgradetypes.QueryAppliedPlanResponse + err = util.Cdc.UnmarshalJSON(bz, &resp) + require.NoError(n.t, err) + + return resp +} + +func (n *NodeConfig) QueryTx(txHash string, overallFlags ...string) sdk.TxResponse { + cmd := []string{ + "babylond", "q", "tx", "--type=hash", txHash, "--output=json", + n.FlagChainID(), + } + + out, _, err := n.containerManager.ExecCmd(n.t, n.Name, append(cmd, overallFlags...), "") + require.NoError(n.t, err) + + var txResp sdk.TxResponse + err = util.Cdc.UnmarshalJSON(out.Bytes(), &txResp) + require.NoError(n.t, err) + + return txResp +} diff --git a/test/e2e/configurer/config/constants.go b/test/e2e/configurer/config/constants.go index 09c584507..72ee9e9b4 100644 --- a/test/e2e/configurer/config/constants.go +++ b/test/e2e/configurer/config/constants.go @@ -7,4 +7,14 @@ const ( PropVoteBlocks float32 = 1.2 // PropBufferBlocks number of blocks used as a calculation buffer PropBufferBlocks float32 = 6 + + // Upgrades + // ForkHeightPreUpgradeOffset how many blocks we allow for fork to run pre upgrade state creation + ForkHeightPreUpgradeOffset int64 = 60 + // MaxRetries for json unmarshalling init chain + MaxRetries = 60 + // PropSubmitBlocks estimated number of blocks it takes to submit for a proposal + PropSubmitBlocks float32 = 1 + // VanillaUpgradeFilePath upgrade vanilla testing + VanillaUpgradeFilePath = "/upgrades/vanilla.json" ) diff --git a/test/e2e/configurer/factory.go b/test/e2e/configurer/factory.go index a04a834cd..985216cdd 100644 --- a/test/e2e/configurer/factory.go +++ b/test/e2e/configurer/factory.go @@ -114,7 +114,7 @@ var ( // TODO currently only one configuration is available. Consider testing upgrades // when necessary func NewBTCTimestampingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, false) + containerManager, err := containers.NewManager(isDebugLogEnabled, false, false) if err != nil { return nil, err } @@ -130,7 +130,7 @@ func NewBTCTimestampingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configu } func NewIBCTransferConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, false) + containerManager, err := containers.NewManager(isDebugLogEnabled, false, false) if err != nil { return nil, err } @@ -147,7 +147,7 @@ func NewIBCTransferConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, // NewBTCTimestampingPhase2Configurer returns a new Configurer for BTC timestamping service (phase 2). func NewBTCTimestampingPhase2Configurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, false) + containerManager, err := containers.NewManager(isDebugLogEnabled, false, false) if err != nil { return nil, err } @@ -164,7 +164,7 @@ func NewBTCTimestampingPhase2Configurer(t *testing.T, isDebugLogEnabled bool) (C // NewBTCTimestampingPhase2RlyConfigurer returns a new Configurer for BTC timestamping service (phase 2), using the Go relayer (rly). func NewBTCTimestampingPhase2RlyConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, true) + containerManager, err := containers.NewManager(isDebugLogEnabled, true, false) if err != nil { return nil, err } @@ -181,7 +181,7 @@ func NewBTCTimestampingPhase2RlyConfigurer(t *testing.T, isDebugLogEnabled bool) // NewBTCStakingConfigurer returns a new Configurer for BTC staking service func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, false) + containerManager, err := containers.NewManager(isDebugLogEnabled, false, false) if err != nil { return nil, err } @@ -195,3 +195,22 @@ func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, containerManager, ), nil } + +// NewSoftwareUpgradeConfigurer returns a new Configurer for Software Upgrade testing +func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradePath string) (Configurer, error) { + containerManager, err := containers.NewManager(isDebugLogEnabled, false, true) + if err != nil { + return nil, err + } + + return NewUpgradeConfigurer(t, + []*chain.Config{ + // we only need 1 chain for testing upgrade + chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, nil), + }, + withUpgrade(baseSetup), // base set up with upgrade + containerManager, + upgradePath, + 0, + ), nil +} diff --git a/test/e2e/configurer/setup.go b/test/e2e/configurer/setup.go index 21308c458..ae2ce6a1b 100644 --- a/test/e2e/configurer/setup.go +++ b/test/e2e/configurer/setup.go @@ -1,6 +1,9 @@ package configurer -import "time" +import ( + "fmt" + "time" +) type setupFn func(configurer Configurer) error @@ -77,3 +80,26 @@ func withIBCTransferChannel(setupHandler setupFn) setupFn { return nil } } + +func withUpgrade(setupHandler setupFn) setupFn { + return func(configurer Configurer) error { + if err := setupHandler(configurer); err != nil { + return err + } + + upgradeConfigurer, ok := configurer.(*UpgradeConfigurer) + if !ok { + return fmt.Errorf("to run with upgrade, %v must be set during initialization", &UpgradeConfigurer{}) + } + + if err := upgradeConfigurer.CreatePreUpgradeState(); err != nil { + return err + } + + if err := upgradeConfigurer.RunUpgrade(); err != nil { + return err + } + + return nil + } +} diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go new file mode 100644 index 000000000..20f5f8bab --- /dev/null +++ b/test/e2e/configurer/upgrade.go @@ -0,0 +1,269 @@ +package configurer + +import ( + "encoding/json" + "fmt" + "os" + "sync" + "testing" + "time" + + govv1 "cosmossdk.io/api/cosmos/gov/v1" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + appparams "github.com/babylonlabs-io/babylon/app/params" + "github.com/babylonlabs-io/babylon/test/e2e/configurer/chain" + "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" + "github.com/babylonlabs-io/babylon/test/e2e/containers" + "github.com/babylonlabs-io/babylon/test/e2e/initialization" +) + +type UpgradeSettings struct { + IsEnabled bool + Version string + ForkHeight int64 // non-zero height implies that this is a fork upgrade. +} + +type UpgradeConfigurer struct { + baseConfigurer + upgradeJsonFilePath string + forkHeight int64 // forkHeight > 0 implies that this is a fork upgrade. Otherwise, proposal upgrade. +} + +var _ Configurer = (*UpgradeConfigurer)(nil) + +// NewUpgradeConfigurer returns a upgrade configurer, if forkHeight is bigger +// than 0 it implies that it is a fork upgrade that does not pass by a gov prop +// if it is set to zero it runs the upgrade by the gov prop. +func NewUpgradeConfigurer(t *testing.T, chainConfigs []*chain.Config, setupTests setupFn, containerManager *containers.Manager, upgradePlanFilePath string, forkHeight int64) Configurer { + t.Helper() + return &UpgradeConfigurer{ + baseConfigurer: baseConfigurer{ + chainConfigs: chainConfigs, + containerManager: containerManager, + setupTests: setupTests, + syncUntilHeight: forkHeight + defaultSyncUntilHeight, + t: t, + }, + forkHeight: forkHeight, + upgradeJsonFilePath: upgradePlanFilePath, + } +} + +func (uc *UpgradeConfigurer) ConfigureChains() error { + errCh := make(chan error, len(uc.chainConfigs)) + var wg sync.WaitGroup + + for _, chainConfig := range uc.chainConfigs { + wg.Add(1) + go func(cc *chain.Config) { + defer wg.Done() + if err := uc.ConfigureChain(cc); err != nil { + errCh <- err + } + }(chainConfig) + } + + // Wait for all goroutines to complete + wg.Wait() + close(errCh) + + // Check if any of the goroutines returned an error + for err := range errCh { + if err != nil { + return err + } + } + + return nil +} + +func (uc *UpgradeConfigurer) ConfigureChain(chainConfig *chain.Config) error { + uc.t.Logf("starting upgrade e2e infrastructure for chain-id: %s", chainConfig.Id) + tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-") + if err != nil { + return err + } + + validatorConfigBytes, err := json.Marshal(chainConfig.ValidatorInitConfigs) + if err != nil { + return err + } + + forkHeight := uc.forkHeight + if forkHeight > 0 { + forkHeight = forkHeight - config.ForkHeightPreUpgradeOffset + } + + chainInitResource, err := uc.containerManager.RunChainInitResource(chainConfig.Id, int(chainConfig.VotingPeriod), int(chainConfig.ExpeditedVotingPeriod), validatorConfigBytes, tmpDir, int(forkHeight)) + if err != nil { + return err + } + + fileName := fmt.Sprintf("%v/%v-encode", tmpDir, chainConfig.Id) + uc.t.Logf("serialized init file for chain-id %v: %v", chainConfig.Id, fileName) + + // loop through the reading and unmarshaling of the init file a total of maxRetries or until error is nil + // without this, test attempts to unmarshal file before docker container is finished writing + var initializedChain initialization.Chain + for i := 0; i < config.MaxRetries; i++ { + initializedChainBytes, _ := os.ReadFile(fileName) + err = json.Unmarshal(initializedChainBytes, &initializedChain) + if err == nil { + break + } + + if i == config.MaxRetries-1 { + return err + } + + if i > 0 { + time.Sleep(1 * time.Second) + } + } + if err := uc.containerManager.PurgeResource(chainInitResource); err != nil { + return err + } + uc.initializeChainConfigFromInitChain(&initializedChain, chainConfig) + return nil +} + +func (uc *UpgradeConfigurer) CreatePreUpgradeState() error { + // send a few bank transfers simulating state data + amountToSend := sdk.NewCoin(appparams.BaseCoinUnit, sdkmath.NewInt(1000000)) // 1bbn + for _, chain := range uc.chainConfigs { + firstNode := chain.NodeConfigs[0] + otherNodes := chain.NodeConfigs[1:] + // first node send to others... + + addresses := make([]string, len(otherNodes)) + for i, node := range otherNodes { + addresses[i] = node.PublicAddress + } + firstNode.BankMultiSendFromNode(addresses, amountToSend.String()) + } + + return nil +} + +func (uc *UpgradeConfigurer) RunSetup() error { + return uc.setupTests(uc) +} + +func (uc *UpgradeConfigurer) RunUpgrade() error { + var err error + if uc.forkHeight > 0 { + uc.runForkUpgrade() + } else { + err = uc.runProposalUpgrade() + } + if err != nil { + return err + } + + // Check if the nodes are running + for chainIndex, chainConfig := range uc.chainConfigs { + chain := uc.baseConfigurer.GetChainConfig(chainIndex) + for validatorIdx := range chainConfig.NodeConfigs { + node := chain.NodeConfigs[validatorIdx] + // Check node status + _, err = node.Status() + if err != nil { + uc.t.Errorf("node is not running after upgrade, chain-id %s, node %s", chainConfig.Id, node.Name) + return err + } + uc.t.Logf("node %s upgraded successfully, address %s", node.Name, node.PublicAddress) + } + } + return nil +} + +func (uc *UpgradeConfigurer) runProposalUpgrade() error { + // submit, deposit, and vote for upgrade proposal + // prop height = current height + voting period + time it takes to submit proposal + small buffer + for _, chainConfig := range uc.chainConfigs { + node, err := chainConfig.GetDefaultNode() + if err != nil { + return err + } + // currentHeight, err := node.QueryCurrentHeight() + // if err != nil { + // return err + // } + // TODO: need to make a way to update proposal height + // chainConfig.UpgradePropHeight = currentHeight + int64(chainConfig.VotingPeriod) + int64(config.PropSubmitBlocks) + int64(config.PropBufferBlocks) + chainConfig.UpgradePropHeight = 25 // at least read from the prop plan file + propID := node.TxGovPropSubmitProposal(uc.upgradeJsonFilePath, node.WalletName) + + chainConfig.TxGovVoteFromAllNodes(propID, govv1.VoteOption_VOTE_OPTION_YES) + } + + // wait till all chains halt at upgrade height + for _, chainConfig := range uc.chainConfigs { + uc.t.Logf("waiting to reach upgrade height on chain %s", chainConfig.Id) + chainConfig.WaitUntilHeight(chainConfig.UpgradePropHeight) + uc.t.Logf("upgrade height reached on chain %s", chainConfig.Id) + } + + // remove all containers so we can upgrade them to the new version + for _, chainConfig := range uc.chainConfigs { + for _, validatorConfig := range chainConfig.NodeConfigs { + err := uc.containerManager.RemoveNodeResource(validatorConfig.Name) + if err != nil { + return err + } + } + } + + // remove all containers so we can upgrade them to the new version + for _, chainConfig := range uc.chainConfigs { + if err := uc.upgradeContainers(chainConfig, chainConfig.UpgradePropHeight); err != nil { + return err + } + } + return nil +} + +func (uc *UpgradeConfigurer) runForkUpgrade() { + for _, chainConfig := range uc.chainConfigs { + uc.t.Logf("waiting to reach fork height on chain %s", chainConfig.Id) + chainConfig.WaitUntilHeight(uc.forkHeight) + uc.t.Logf("fork height reached on chain %s", chainConfig.Id) + } +} + +func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHeight int64) error { + // upgrade containers to the locally compiled daemon + uc.t.Logf("starting upgrade for chain-id: %s...", chainConfig.Id) + uc.containerManager.CurrentRepository = containers.BabylonContainerName + + errCh := make(chan error, len(chainConfig.NodeConfigs)) + var wg sync.WaitGroup + + for _, node := range chainConfig.NodeConfigs { + wg.Add(1) + go func(node *chain.NodeConfig) { + defer wg.Done() + if err := node.Run(); err != nil { + errCh <- err + } + }(node) + } + + // Wait for all goroutines to complete + wg.Wait() + close(errCh) + + // Check if any of the goroutines returned an error + for err := range errCh { + if err != nil { + return err + } + } + + uc.t.Logf("waiting to upgrade containers on chain %s", chainConfig.Id) + chainConfig.WaitUntilHeight(propHeight + 1) + uc.t.Logf("upgrade successful on chain %s", chainConfig.Id) + return nil +} diff --git a/test/e2e/containers/config.go b/test/e2e/containers/config.go index 9f15dcb1c..18b4f91e2 100644 --- a/test/e2e/containers/config.go +++ b/test/e2e/containers/config.go @@ -3,14 +3,22 @@ package containers // ImageConfig contains all images and their respective tags // needed for running e2e tests. type ImageConfig struct { + // IBC relayer for cosmos-SDK RelayerRepository string RelayerTag string + + CurrentRepository string } //nolint:deadcode const ( - // name of babylon container produced by running `make localnet-build-env` + // Images that do not have specified tag, latest will be used by default. + // name of babylon image produced by running `make build-docker` BabylonContainerName = "babylonlabs-io/babylond" + // name of babylon image produced by running `make build-docker-e2e` + BabylonContainerNameBeforeUpgrade = "babylonlabs-io/babylond-before-upgrade" + // name of the image produced by running `make e2e-init-chain` in contrib/images + InitChainContainerE2E = "babylonlabs-io/babylond-e2e-init-chain" hermesRelayerRepository = "informalsystems/hermes" hermesRelayerTag = "v1.8.2" @@ -23,18 +31,23 @@ const ( // NewImageConfig returns ImageConfig needed for running e2e test. // If isUpgrade is true, returns images for running the upgrade // If isFork is true, utilizes provided fork height to initiate fork logic -func NewImageConfig(isCosmosRelayer bool) ImageConfig { +func NewImageConfig(isCosmosRelayer, isUpgrade bool) (ic ImageConfig) { + ic = ImageConfig{ + CurrentRepository: BabylonContainerName, + } + + if isUpgrade { + // starts at the older version and later upgrades it to current branch... BabylonContainerName + ic.CurrentRepository = BabylonContainerNameBeforeUpgrade + } + if isCosmosRelayer { - config := ImageConfig{ - RelayerRepository: cosmosRelayerRepository, - RelayerTag: cosmosRelayerTag, - } - return config + ic.RelayerRepository = cosmosRelayerRepository + ic.RelayerTag = cosmosRelayerTag + return ic } else { - config := ImageConfig{ - RelayerRepository: hermesRelayerRepository, - RelayerTag: hermesRelayerTag, - } - return config + ic.RelayerRepository = hermesRelayerRepository + ic.RelayerTag = hermesRelayerTag + return ic } } diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 09782d7f1..2de3bc413 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -13,6 +13,7 @@ import ( "github.com/ory/dockertest/v3" "github.com/ory/dockertest/v3/docker" "github.com/stretchr/testify/require" + "golang.org/x/sync/errgroup" ) const ( @@ -39,9 +40,9 @@ type Manager struct { // NewManager creates a new Manager instance and initializes // all Docker specific utilities. Returns an error if initialization fails. -func NewManager(isDebugLogEnabled bool, isCosmosRelayer bool) (docker *Manager, err error) { +func NewManager(isDebugLogEnabled bool, isCosmosRelayer, isUpgrade bool) (docker *Manager, err error) { docker = &Manager{ - ImageConfig: NewImageConfig(isCosmosRelayer), + ImageConfig: NewImageConfig(isCosmosRelayer, isUpgrade), resources: make(map[string]*dockertest.Resource), isDebugLogEnabled: isDebugLogEnabled, } @@ -252,7 +253,7 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st runOpts := &dockertest.RunOptions{ Name: containerName, - Repository: BabylonContainerName, + Repository: m.CurrentRepository, NetworkID: m.network.Network.ID, User: "root:root", Entrypoint: []string{ @@ -264,6 +265,7 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st Mounts: []string{ fmt.Sprintf("%s/:%s", valCondifDir, BabylonHomePath), fmt.Sprintf("%s/bytecode:/bytecode", pwd), + fmt.Sprintf("%s/upgrades:/upgrades", pwd), }, } @@ -321,17 +323,20 @@ func (m *Manager) RemoveNodeResource(containerName string) error { } // ClearResources removes all outstanding Docker resources created by the Manager. -func (m *Manager) ClearResources() error { +func (m *Manager) ClearResources() (e error) { + g := new(errgroup.Group) for _, resource := range m.resources { - if err := m.pool.Purge(resource); err != nil { - return err - } + resource := resource + g.Go(func() error { + return m.pool.Purge(resource) + }) } - if err := m.pool.RemoveNetwork(m.network); err != nil { + if err := g.Wait(); err != nil { return err } - return nil + + return m.pool.RemoveNetwork(m.network) } func noRestart(config *docker.HostConfig) { @@ -340,3 +345,38 @@ func noRestart(config *docker.HostConfig) { Name: "no", } } + +// RunChainInitResource runs a chain init container to initialize genesis and configs for a chain with chainId. +// The chain is to be configured with chainVotingPeriod and validators deserialized from validatorConfigBytes. +// The genesis and configs are to be mounted on the init container as volume on mountDir path. +// Returns the container resource and error if any. This method does not Purge the container. The caller +// must deal with removing the resource. +func (m *Manager) RunChainInitResource(chainId string, chainVotingPeriod, chainExpeditedVotingPeriod int, validatorConfigBytes []byte, mountDir string, forkHeight int) (*dockertest.Resource, error) { + votingPeriodDuration := time.Duration(chainVotingPeriod * 1000000000) + expeditedVotingPeriodDuration := time.Duration(chainExpeditedVotingPeriod * 1000000000) + + initResource, err := m.pool.RunWithOptions( + &dockertest.RunOptions{ + Name: chainId, + Repository: InitChainContainerE2E, + NetworkID: m.network.Network.ID, + Cmd: []string{ + fmt.Sprintf("--data-dir=%s", mountDir), + fmt.Sprintf("--chain-id=%s", chainId), + fmt.Sprintf("--config=%s", validatorConfigBytes), + fmt.Sprintf("--voting-period=%v", votingPeriodDuration), + fmt.Sprintf("--expedited-voting-period=%v", expeditedVotingPeriodDuration), + fmt.Sprintf("--fork-height=%v", forkHeight), + }, + User: "root:root", + Mounts: []string{ + fmt.Sprintf("%s:%s", mountDir, mountDir), + }, + }, + noRestart, + ) + if err != nil { + return nil, err + } + return initResource, nil +} diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 4c877c6c8..cc78d6b15 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -35,3 +35,8 @@ func TestBTCTimestampingPhase2RlyTestSuite(t *testing.T) { func TestBTCStakingTestSuite(t *testing.T) { suite.Run(t, new(BTCStakingTestSuite)) } + +// TestSoftwareUpgradeTestSuite tests software upgrade protocol end-to-end +func TestSoftwareUpgradeTestSuite(t *testing.T) { + suite.Run(t, new(SoftwareUpgradeVanillaTestSuite)) +} diff --git a/test/e2e/ibc_transfer_e2e_test.go b/test/e2e/ibc_transfer_e2e_test.go index c1521a467..7e3597f64 100644 --- a/test/e2e/ibc_transfer_e2e_test.go +++ b/test/e2e/ibc_transfer_e2e_test.go @@ -38,9 +38,9 @@ func (s *IBCTransferTestSuite) TearDownSuite() { } func (s *IBCTransferTestSuite) Test1IBCTransfer() { - babylonChain := s.configurer.GetChainConfig(0) + bbnChain := s.configurer.GetChainConfig(0) - babylonNode, err := babylonChain.GetNodeAtIndex(2) + babylonNode, err := bbnChain.GetNodeAtIndex(2) s.NoError(err) sender := initialization.ValidatorWalletName diff --git a/test/e2e/initialization/config.go b/test/e2e/initialization/config.go index 3e7119ae0..930f9d66a 100644 --- a/test/e2e/initialization/config.go +++ b/test/e2e/initialization/config.go @@ -6,7 +6,7 @@ import ( "path/filepath" "time" - "cosmossdk.io/math" + sdkmath "cosmossdk.io/math" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -17,6 +17,8 @@ import ( crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" staketypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/gogoproto/proto" @@ -67,9 +69,9 @@ const ( ) var ( - StakeAmountIntA = math.NewInt(StakeAmountA) + StakeAmountIntA = sdkmath.NewInt(StakeAmountA) StakeAmountCoinA = sdk.NewCoin(BabylonDenom, StakeAmountIntA) - StakeAmountIntB = math.NewInt(StakeAmountB) + StakeAmountIntB = sdkmath.NewInt(StakeAmountB) StakeAmountCoinB = sdk.NewCoin(BabylonDenom, StakeAmountIntB) InitBalanceStrA = fmt.Sprintf("%d%s", BabylonBalanceA, BabylonDenom) @@ -216,6 +218,11 @@ func initGenesis(chain *internalChain, votingPeriod, expeditedVotingPeriod time. return err } + err = updateModuleGenesis(appGenState, govtypes.ModuleName, &govv1.GenesisState{}, updateGovGenesis(votingPeriod, expeditedVotingPeriod)) + if err != nil { + return err + } + err = updateModuleGenesis(appGenState, minttypes.ModuleName, &minttypes.GenesisState{}, updateMintGenesis) if err != nil { return err @@ -288,6 +295,14 @@ func updateBankGenesis(bankGenState *banktypes.GenesisState) { }) } +func updateGovGenesis(votingPeriod, expeditedVotingPeriod time.Duration) func(govGenState *govv1.GenesisState) { + return func(govGenState *govv1.GenesisState) { + govGenState.Params.MinDeposit = sdk.NewCoins(sdk.NewCoin(BabylonDenom, sdkmath.NewInt(100))) + govGenState.Params.VotingPeriod = &votingPeriod + govGenState.Params.ExpeditedVotingPeriod = &expeditedVotingPeriod + } +} + func updateMintGenesis(mintGenState *minttypes.GenesisState) { mintGenState.Params.MintDenom = BabylonDenom } @@ -299,7 +314,7 @@ func updateStakeGenesis(stakeGenState *staketypes.GenesisState) { MaxEntries: 7, HistoricalEntries: 10000, UnbondingTime: staketypes.DefaultUnbondingTime, - MinCommissionRate: math.LegacyZeroDec(), + MinCommissionRate: sdkmath.LegacyZeroDec(), } } diff --git a/test/e2e/initialization/export.go b/test/e2e/initialization/export.go index 663250876..ebe2c2522 100644 --- a/test/e2e/initialization/export.go +++ b/test/e2e/initialization/export.go @@ -2,8 +2,6 @@ package initialization import ( "fmt" - - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) type ChainMeta struct { @@ -17,7 +15,6 @@ type Node struct { Mnemonic string `json:"mnemonic"` PublicAddress string `json:"publicAddress"` WalletName string `json:"walletName"` - SecretKey cryptotypes.PrivKey PublicKey []byte `json:"publicKey"` PeerId string `json:"peerId"` IsValidator bool `json:"isValidator"` diff --git a/test/e2e/initialization/node.go b/test/e2e/initialization/node.go index 4346e7b31..17eddb24d 100644 --- a/test/e2e/initialization/node.go +++ b/test/e2e/initialization/node.go @@ -248,7 +248,6 @@ func (n *internalNode) export() *Node { Mnemonic: n.mnemonic, PublicAddress: addr.String(), WalletName: n.keyInfo.Name, - SecretKey: n.privateKey, PublicKey: pub.Bytes(), PeerId: n.peerId, IsValidator: n.isValidator, diff --git a/test/e2e/software_upgrade_e2e_test.go b/test/e2e/software_upgrade_e2e_test.go new file mode 100644 index 000000000..3cac9f9c9 --- /dev/null +++ b/test/e2e/software_upgrade_e2e_test.go @@ -0,0 +1,50 @@ +package e2e + +import ( + "github.com/stretchr/testify/suite" + + "github.com/babylonlabs-io/babylon/test/e2e/configurer" + "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" +) + +type SoftwareUpgradeVanillaTestSuite struct { + suite.Suite + + configurer configurer.Configurer +} + +func (s *SoftwareUpgradeVanillaTestSuite) SetupSuite() { + s.T().Log("setting up e2e integration test suite...") + var err error + + s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.VanillaUpgradeFilePath) + s.NoError(err) + err = s.configurer.ConfigureChains() + s.NoError(err) + err = s.configurer.RunSetup() // upgrade happens at the setup of configurer. + s.NoError(err) +} + +func (s *SoftwareUpgradeVanillaTestSuite) TearDownSuite() { + err := s.configurer.ClearResources() + s.Require().NoError(err) +} + +// TestUpgradeVanilla only checks that new fp was added. +func (s *SoftwareUpgradeVanillaTestSuite) TestUpgradeVanilla() { + // chain is already upgraded, only checks for differences in state are expected + chainA := s.configurer.GetChainConfig(0) + chainA.WaitUntilHeight(30) // five blocks more than upgrade + + n, err := chainA.GetDefaultNode() + s.NoError(err) + + expectedUpgradeHeight := int64(25) + + // makes sure that the upgrade was actually executed + resp := n.QueryAppliedPlan("vanilla") + s.EqualValues(expectedUpgradeHeight, resp.Height, "the plan should be applied at the height 25") + + fps := n.QueryFinalityProviders() + s.Len(fps, 1, "it should have one finality provider, since the vanilla upgrade just added a new one") +} diff --git a/test/e2e/upgrades/vanilla.json b/test/e2e/upgrades/vanilla.json new file mode 100644 index 000000000..7461f0b22 --- /dev/null +++ b/test/e2e/upgrades/vanilla.json @@ -0,0 +1,14 @@ +{ + "title": "any title", + "summary": "any summary", + "messages": [ + { + "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + "authority": "bbn10d07y265gmmuvt4z0w9aw880jnsr700jduz5f2", + "plan": { "name": "vanilla", "info": "Msg info", "height": 25 } + } + ], + "deposit": "500000000ubbn", + "initial_deposit": "500000000ubbn", + "initialDeposit": "500000000ubbn" +} \ No newline at end of file diff --git a/wasmbinding/testdata/README.md b/wasmbinding/testdata/README.md index cd0a7ef09..200456134 100644 --- a/wasmbinding/testdata/README.md +++ b/wasmbinding/testdata/README.md @@ -8,7 +8,6 @@ This approach enables us to specify which branch from bindings library we want t Until custom babylon api is stable this approach enables faster iteration than publishing wasm blobs from bindings library directly. - ## Artifacts We are storing current version of artifacts in repo to speed up the CI. From 61cfcaa1dd0ec84f9c1bbf071a00e8f87b7f7bb6 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 29 Jul 2024 13:27:41 -0300 Subject: [PATCH 02/89] chore: only add upgrade if build with e2e tag --- Makefile | 3 ++- app/app.go | 7 ++----- app/e2e_include_upgrades.go | 9 +++++++++ contrib/images/Makefile | 4 ++++ contrib/images/babylond/Dockerfile | 1 + go.mod | 2 +- 6 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 app/e2e_include_upgrades.go diff --git a/Makefile b/Makefile index aadf3bde4..058d5fc9c 100644 --- a/Makefile +++ b/Makefile @@ -427,7 +427,8 @@ dockerNetworkList=$($(DOCKER) network ls --filter name=bbn-testnet --format {{.I build-docker: ## Build babylond Docker image $(MAKE) -C contrib/images babylond -build-docker-e2e: build-docker +build-docker-e2e: + $(MAKE) -C contrib/images babylond-e2e $(MAKE) -C contrib/images babylond-before-upgrade $(MAKE) -C contrib/images e2e-init-chain diff --git a/app/app.go b/app/app.go index 4e019d25c..541bcd8d3 100644 --- a/app/app.go +++ b/app/app.go @@ -94,7 +94,6 @@ import ( "github.com/spf13/cast" "github.com/babylonlabs-io/babylon/app/upgrades" - "github.com/babylonlabs-io/babylon/app/upgrades/vanilla" bbn "github.com/babylonlabs-io/babylon/types" appkeepers "github.com/babylonlabs-io/babylon/app/keepers" @@ -159,10 +158,8 @@ var ( } // software upgrades and forks - Upgrades = []upgrades.Upgrade{ - vanilla.Upgrade, - } - Forks = []upgrades.Fork{} + Upgrades = []upgrades.Upgrade{} + Forks = []upgrades.Fork{} ) func init() { diff --git a/app/e2e_include_upgrades.go b/app/e2e_include_upgrades.go new file mode 100644 index 000000000..9d6af8d51 --- /dev/null +++ b/app/e2e_include_upgrades.go @@ -0,0 +1,9 @@ +//go:build e2e + +package app + +import "github.com/babylonlabs-io/babylon/app/upgrades/vanilla" + +func init() { + Upgrades = append(Upgrades, vanilla.Upgrade) +} diff --git a/contrib/images/Makefile b/contrib/images/Makefile index 214ebbe5a..c0afef21b 100644 --- a/contrib/images/Makefile +++ b/contrib/images/Makefile @@ -7,6 +7,10 @@ all: babylond cosmos-relayer babylond: babylond-rmi docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile ${BABYLON_FULL_PATH} +babylond-e2e: babylond-rmi + docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile ${BABYLON_FULL_PATH} \ + --build-arg BUILD_TAGS="e2e" + babylond-before-upgrade: docker rmi babylonlabs-io/babylond-before-upgrade 2>/dev/null; true && \ docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile \ diff --git a/contrib/images/babylond/Dockerfile b/contrib/images/babylond/Dockerfile index 76c315562..50f7857b8 100644 --- a/contrib/images/babylond/Dockerfile +++ b/contrib/images/babylond/Dockerfile @@ -3,6 +3,7 @@ FROM golang:1.21 AS build-env # Version to build. Default is empty ARG VERSION +ARG BUILD_TAGS="" ARG LEDGER_ENABLED="false" # Cosmos build options ARG COSMOS_BUILD_OPTIONS="" diff --git a/go.mod b/go.mod index e8ba3e373..9ab2153c5 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,7 @@ require ( github.com/vulpine-io/io-test v1.0.0 go.uber.org/zap v1.26.0 golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 + golang.org/x/sync v0.7.0 google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de ) @@ -247,7 +248,6 @@ require ( golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/oauth2 v0.18.0 // indirect - golang.org/x/sync v0.7.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.20.0 // indirect google.golang.org/api v0.162.0 // indirect From c36b17db1cf0314d5def9f28b5aaad63e2db6c23 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 29 Jul 2024 21:42:46 -0300 Subject: [PATCH 03/89] feat: add launch upgrade --- app/upgrades/launch/README.md | 4 + app/upgrades/launch/data/btc_headers.json | 88 +++++++++++++++ app/upgrades/launch/upgrades.go | 105 ++++++++++++++++++ app/upgrades/launch/upgrades_test.go | 105 ++++++++++++++++++ .../cmd/genhelpers/set_btc_headers.go | 4 +- x/btclightclient/keeper/keeper.go | 16 +++ 6 files changed, 320 insertions(+), 2 deletions(-) create mode 100644 app/upgrades/launch/README.md create mode 100644 app/upgrades/launch/data/btc_headers.json create mode 100644 app/upgrades/launch/upgrades.go create mode 100644 app/upgrades/launch/upgrades_test.go diff --git a/app/upgrades/launch/README.md b/app/upgrades/launch/README.md new file mode 100644 index 000000000..45630d32a --- /dev/null +++ b/app/upgrades/launch/README.md @@ -0,0 +1,4 @@ +# Launch + +This folder contains a software upgrade for testing purposes. +DO NOT USE IN PRODUCTION! diff --git a/app/upgrades/launch/data/btc_headers.json b/app/upgrades/launch/data/btc_headers.json new file mode 100644 index 000000000..cd74a8382 --- /dev/null +++ b/app/upgrades/launch/data/btc_headers.json @@ -0,0 +1,88 @@ +{ + "btc_headers": [ + { + "header": "0000002095156a30ef4e6c9764c0ce83fac51a37365b2092bd39bdbfd038f5b98f00000077f14ee2b34b7dcbb7e3fc624184b919b74cd047837728593140ee21e59cc5bee4c9a766644d011e4e202800", + "hash": "0000010a767aed4930b7cf4aa0f90b4cc23d8e5375142c0a626aba09ff411f06", + "height": 206500, + "work": "180357618" + }, + { + "header": "00000020061f41ff09ba6a620a2c1475538e3dc24c0bf9a04acfb73049ed7a760a0100004a7b4cec7be4c56a3dfdb833e94a5ff5ce4bdf5b5b0a599a39ef717fffe914b4ecd0a766644d011e822f6102", + "hash": "0000000a36d6c67675cbbbf1f8dc5cafd5def468b5b5e063768ddc3147e065d7", + "height": 206501, + "work": "180357618" + }, + { + "header": "00000020d765e04731dc8d7663e0b5b568f4ded5af5cdcf8f1bbcb7576c6d6360a000000fb1a404fe53effdb9c0769966614fbe7cd7d7d537068339fc38a4c41e14ed6b1bfd1a766644d011eddc8aa00", + "hash": "0000008a5a47ffe1e621ee2d4c8f4baeef953da8e915d6837ccbaa7a7b877d2c", + "height": 206502, + "work": "180357618" + }, + { + "header": "000000202c7d877b7aaacb7c83d615e9a83d95efae4b8f4c2dee21e6e1ff475a8a000000aa2d38699ab5195fb8d75512e639f3467aacb0346bf5478d529c969c6aa398fb64d3a766644d011ee2dc5f01", + "hash": "000000c7b179e7283c8641d1d1ff6a0b202213a19463490a79163aef0ccfad1e", + "height": 206503, + "work": "180357618" + }, + { + "header": "000000201eadcf0cef3a16790a496394a11322200b6affd1d141863c28e779b1c70000006b58a84c6d1ba0c1841592fd5855f54e354e2b2a4d9467f57c9a22cb7b8a6b4984d3a766644d011e50d96c01", + "hash": "000000fc83896a94e89aae093c648bac3841de08a0dbe4ab1719db22796442b8", + "height": 206504, + "work": "180357618" + }, + { + "header": "00000020b842647922db1917abe4dba008de4138ac8b643c09ae9ae8946a8983fc0000001e2eafc39aed81b433b9dc5fbf4916460f414c9333ace37bb99a300950ff76241fd5a766644d011ecffa8c00", + "hash": "000000a839a452cfa49121973e1ecd17838b74fd3238abfc5e28a8d04fa76fd9", + "height": 206505, + "work": "180357618" + }, + { + "header": "00000020d96fa74fd0a8285efcab3832fd748b8317cd1e3e972191a4cf52a439a800000092e19ee24b41b4debca252714de700a8573c610ad277866abd238ae527d899d40dd6a766644d011e053a5c00", + "hash": "000000edb41b0c424a7ffbbaf5704daf494d9209013ca10b3f76d66610d77d99", + "height": 206506, + "work": "180357618" + }, + { + "header": "00000020997dd71066d6763f0ba13c0109924d49af4d70f5bafb7f4a420c1bb4ed000000fa2603a7097ff5d5fb2ca0b5dc33fce8ae8cdc44916b736cabdeef8abab05a7b38d6a766644d011ee7bbe900", + "hash": "0000006516e2ff853d1fc48e476df001420e7e5b740ea178b7edc5f557e27c58", + "height": 206507, + "work": "180357618" + }, + { + "header": "00000020587ce257f5c5edb778a10e745b7e0e4201f06d478ec41f3d85ffe21665000000cde05d3c4355c5aef220d5b16ffb8339ae979c513f8af0bc5c74d21ac8a4fd2e45d7a766644d011eabacbe00", + "hash": "0000001ec310dc0a5113ae10f00d944f01562c0a4c50c8ee41ff00b164cb81cc", + "height": 206508, + "work": "180357618" + }, + { + "header": "00000020cc81cb64b100ff41eec8504c0a2c56014f940df010ae13510adc10c31e0000006433905cd152679dc2620d09a44203589743d88c181a0342811225ff823b484f85d8a766644d011e077d7300", + "hash": "000000e04fd41669fac0a6fbf595e795d841ca1f1f3df82410b7be8d8956c0e0", + "height": 206509, + "work": "180357618" + }, + { + "header": "00000020e0c056898dbeb71024f83d1f1fca41d895e795f5fba6c0fa6916d44fe0000000dfb1582ec3ecf5c35a7ca4a75624d17517373371923a19dc1729f62f24402f0371daa766644d011e605fcd00", + "hash": "000000dc9ea403aadca79175d75ab6a09f21178955e1aa92ad134d1f35639317", + "height": 206510, + "work": "180357618" + }, + { + "header": "00000020179363351f4d13ad92aae1558917219fa0b65ad77591a7dcaa03a49edc0000007b03a2a905ac70c86e3568978c8a1e5f4aa720999d3dbd2e2bdfffbc3b7ecf6306dba766644d011ed6383600", + "hash": "0000008cb36ab72c793033a25ccb5ea266a63c6d8a3a8774db9574bd2f099a26", + "height": 206511, + "work": "180357618" + }, + { + "header": "00000020269a092fbd7495db74873a8a6d3ca666a25ecb5ca23330792cb76ab38c000000d6ad13ceaa5c27b1e1e2d68b0080cc40b82b44faf895e3f819edfae1709aa74587dba766644d011e93fc8a00", + "hash": "000000e698603e02a0ae61186f6b6294f8f58732bcfb1bf7c5c8cc8c25b17134", + "height": 206512, + "work": "180357618" + }, + { + "header": "000000203471b1258cccc8c5f71bfbbc3287f5f894626b6f1861aea0023e6098e60000002d05f3d038ee2535da13f928afa100e9dac12598c11afc19b0e952a22bc924d1ecdba766644d011e5eb27d00", + "hash": "0000001ea82bcd9bb5ada7c186a3f1b02413fd0e5d873e44825ca628e5511496", + "height": 206513, + "work": "180357618" + } + ] +} \ No newline at end of file diff --git a/app/upgrades/launch/upgrades.go b/app/upgrades/launch/upgrades.go new file mode 100644 index 000000000..2c6e18666 --- /dev/null +++ b/app/upgrades/launch/upgrades.go @@ -0,0 +1,105 @@ +// This code is only for testing purposes. +// DO NOT USE IN PRODUCTION! + +package launch + +import ( + "context" + "errors" + "fmt" + "os" + "path/filepath" + "sort" + + 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" + "github.com/babylonlabs-io/babylon/cmd/babylond/cmd/genhelpers" + btclightkeeper "github.com/babylonlabs-io/babylon/x/btclightclient/keeper" + btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" +) + +var Upgrade = upgrades.Upgrade{ + UpgradeName: "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) + + propLaunch(ctx, &keepers.BTCLightClientKeeper) + + return mm.RunMigrations(ctx, cfg, fromVM) + } +} + +// 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 data/btc_headers.json path. +func LoadBTCHeadersFromData() ([]*btclighttypes.BTCHeaderInfo, error) { + pwd, err := os.Getwd() + if err != nil { + return nil, err + } + + btcHeadersFilePath := filepath.Join(pwd, "data/btc_headers.json") + gs, err := genhelpers.LoadBtcLightGenStateFromFile(appparams.DefaultEncodingConfig().Codec, btcHeadersFilePath) + if err != nil { + return nil, err + } + return gs.BtcHeaders, nil +} + +func insertBtcHeaders( + ctx sdk.Context, + k *btclightkeeper.Keeper, + headers []*btclighttypes.BTCHeaderInfo, +) error { + if len(headers) == 0 { + return errors.New("no headers to insert") + } + + // sort by height to make sure it is deterministic + sort.Slice(headers, func(i, j int) bool { + return headers[i].Height > headers[j].Height + }) + + for _, header := range headers { + if err := header.Validate(); err != nil { + return err + } + } + k.InsertHeaderInfos(ctx, headers) + + allBlocks := k.GetMainChainFromWithLimit(ctx, 0, 1) + isRetarget := btclighttypes.IsRetargetBlock(allBlocks[0], &chaincfg.MainNetParams) + if !isRetarget { + return fmt.Errorf("first header be a difficulty adjustment block") + } + return nil +} diff --git a/app/upgrades/launch/upgrades_test.go b/app/upgrades/launch/upgrades_test.go new file mode 100644 index 000000000..53c27e3df --- /dev/null +++ b/app/upgrades/launch/upgrades_test.go @@ -0,0 +1,105 @@ +package launch_test + +import ( + "fmt" + "testing" + "time" + + "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/header" + "cosmossdk.io/x/upgrade" + upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/babylonlabs-io/babylon/app" + v1 "github.com/babylonlabs-io/babylon/app/upgrades/launch" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/suite" +) + +const ( + DummyUpgradeHeight = 5 +) + +type UpgradeTestSuite struct { + suite.Suite + + ctx sdk.Context + app *app.BabylonApp + preModule appmodule.HasPreBlocker +} + +func (s *UpgradeTestSuite) SetupTest() { + // add the upgrade plan + app.Upgrades = append(app.Upgrades, v1.Upgrade) + + // set up app + s.app = app.Setup(s.T(), false) + s.ctx = s.app.BaseApp.NewContextLegacy(false, tmproto.Header{Height: 1, ChainID: "babylon-1", Time: time.Now().UTC()}) + s.preModule = upgrade.NewAppModule(s.app.UpgradeKeeper, s.app.AccountKeeper.AddressCodec()) +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(UpgradeTestSuite)) +} + +func (s *UpgradeTestSuite) TestUpgradePayments() { + oldHeadersLen := 0 + + testCases := []struct { + msg string + pre_update func() + update func() + post_update func() + }{ + { + "Test launch software upgrade gov prop", + func() { + allBtcHeaders := s.app.BTCLightClientKeeper.GetMainChainFrom(s.ctx, 0) + oldHeadersLen = len(allBtcHeaders) + }, + func() { + // inject upgrade plan + s.ctx = s.ctx.WithBlockHeight(DummyUpgradeHeight - 1) + plan := upgradetypes.Plan{Name: v1.Upgrade.UpgradeName, Height: DummyUpgradeHeight} + err := s.app.UpgradeKeeper.ScheduleUpgrade(s.ctx, plan) + s.NoError(err) + + // ensure upgrade plan exists + actualPlan, err := s.app.UpgradeKeeper.GetUpgradePlan(s.ctx) + s.NoError(err) + s.Equal(plan, actualPlan) + + // execute upgrade + s.ctx = s.ctx.WithHeaderInfo(header.Info{Height: DummyUpgradeHeight, Time: s.ctx.BlockTime().Add(time.Second)}).WithBlockHeight(DummyUpgradeHeight) + s.NotPanics(func() { + _, err := s.preModule.PreBlock(s.ctx) + s.NoError(err) + }) + }, + func() { + // ensure the btc headers were added + allBtcHeaders := s.app.BTCLightClientKeeper.GetMainChainFrom(s.ctx, 0) + + btcHeaders, err := v1.LoadBTCHeadersFromData() + s.NoError(err) + lenHeadersInserted := len(btcHeaders) + + newHeadersLen := len(allBtcHeaders) + s.Equal(newHeadersLen, oldHeadersLen+lenHeadersInserted) + + // ensure the headers were inserted at the end + s.Equal(allBtcHeaders[len(allBtcHeaders)-lenHeadersInserted:], btcHeaders) + }, + }, + } + + for _, tc := range testCases { + s.Run(fmt.Sprintf("Case %s", tc.msg), func() { + s.SetupTest() // reset + + tc.pre_update() + tc.update() + tc.post_update() + }) + } +} diff --git a/cmd/babylond/cmd/genhelpers/set_btc_headers.go b/cmd/babylond/cmd/genhelpers/set_btc_headers.go index db30b2f04..5ddfa3b36 100644 --- a/cmd/babylond/cmd/genhelpers/set_btc_headers.go +++ b/cmd/babylond/cmd/genhelpers/set_btc_headers.go @@ -51,7 +51,7 @@ Possible content of 'btc_headers.json' is config := server.GetServerContextFromCmd(cmd).Config config.SetRoot(clientCtx.HomeDir) - inputBtcHeaders, err := getBtcLightGenStateFromFile(clientCtx.Codec, args[0]) + inputBtcHeaders, err := LoadBtcLightGenStateFromFile(clientCtx.Codec, args[0]) if err != nil { return err } @@ -103,7 +103,7 @@ Possible content of 'btc_headers.json' is return cmd } -func getBtcLightGenStateFromFile(cdc codec.Codec, inputFilePath string) (*btclighttypes.GenesisState, error) { +func LoadBtcLightGenStateFromFile(cdc codec.Codec, inputFilePath string) (*btclighttypes.GenesisState, error) { filePath := filepath.Clean(inputFilePath) if !cmtos.FileExists(filePath) { return nil, fmt.Errorf("input file %s does not exists", filePath) diff --git a/x/btclightclient/keeper/keeper.go b/x/btclightclient/keeper/keeper.go index 64b7508ba..74b36409e 100644 --- a/x/btclightclient/keeper/keeper.go +++ b/x/btclightclient/keeper/keeper.go @@ -206,6 +206,22 @@ func (k Keeper) GetMainChainFrom(ctx context.Context, startHeight uint64) []*typ return headers } +// GetMainChainFromWithLimit returns the current canonical chain from the given height up to the tip +// If the height is higher than the tip, it returns an empty slice +// If startHeight is 0, it returns the entire main chain +func (k Keeper) GetMainChainFromWithLimit(ctx context.Context, startHeight, limit uint64) []*types.BTCHeaderInfo { + headers := make([]*types.BTCHeaderInfo, 0, limit) + fn := func(header *types.BTCHeaderInfo) bool { + if len(headers) >= int(limit) { + return true + } + headers = append(headers, header) + return false + } + k.headersState(ctx).IterateForwardHeaders(startHeight, fn) + return headers +} + // GetMainChainUpTo returns the current canonical chain as a collection of block headers // starting from the tip and ending on the header that has `depth` distance from it. func (k Keeper) GetMainChainUpTo(ctx context.Context, depth uint64) []*types.BTCHeaderInfo { From 3a40a02407a67cc67263cd6ff4b59d6e3d7a2379 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 29 Jul 2024 21:44:40 -0300 Subject: [PATCH 04/89] chore: move name to launch signet --- app/upgrades/{launch => launchsignet}/README.md | 2 +- app/upgrades/{launch => launchsignet}/data/btc_headers.json | 0 app/upgrades/{launch => launchsignet}/upgrades.go | 6 +++--- app/upgrades/{launch => launchsignet}/upgrades_test.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename app/upgrades/{launch => launchsignet}/README.md (84%) rename app/upgrades/{launch => launchsignet}/data/btc_headers.json (100%) rename app/upgrades/{launch => launchsignet}/upgrades.go (97%) rename app/upgrades/{launch => launchsignet}/upgrades_test.go (96%) diff --git a/app/upgrades/launch/README.md b/app/upgrades/launchsignet/README.md similarity index 84% rename from app/upgrades/launch/README.md rename to app/upgrades/launchsignet/README.md index 45630d32a..39a776a61 100644 --- a/app/upgrades/launch/README.md +++ b/app/upgrades/launchsignet/README.md @@ -1,4 +1,4 @@ -# Launch +# Launch Signet This folder contains a software upgrade for testing purposes. DO NOT USE IN PRODUCTION! diff --git a/app/upgrades/launch/data/btc_headers.json b/app/upgrades/launchsignet/data/btc_headers.json similarity index 100% rename from app/upgrades/launch/data/btc_headers.json rename to app/upgrades/launchsignet/data/btc_headers.json diff --git a/app/upgrades/launch/upgrades.go b/app/upgrades/launchsignet/upgrades.go similarity index 97% rename from app/upgrades/launch/upgrades.go rename to app/upgrades/launchsignet/upgrades.go index 2c6e18666..7a841b2ab 100644 --- a/app/upgrades/launch/upgrades.go +++ b/app/upgrades/launchsignet/upgrades.go @@ -1,7 +1,7 @@ // This code is only for testing purposes. // DO NOT USE IN PRODUCTION! -package launch +package launchsignet import ( "context" @@ -26,7 +26,7 @@ import ( ) var Upgrade = upgrades.Upgrade{ - UpgradeName: "launch", + UpgradeName: "launch-signet", CreateUpgradeHandler: CreateUpgradeHandler, StoreUpgrades: store.StoreUpgrades{}, } @@ -97,7 +97,7 @@ func insertBtcHeaders( k.InsertHeaderInfos(ctx, headers) allBlocks := k.GetMainChainFromWithLimit(ctx, 0, 1) - isRetarget := btclighttypes.IsRetargetBlock(allBlocks[0], &chaincfg.MainNetParams) + isRetarget := btclighttypes.IsRetargetBlock(allBlocks[0], &chaincfg.SigNetParams) if !isRetarget { return fmt.Errorf("first header be a difficulty adjustment block") } diff --git a/app/upgrades/launch/upgrades_test.go b/app/upgrades/launchsignet/upgrades_test.go similarity index 96% rename from app/upgrades/launch/upgrades_test.go rename to app/upgrades/launchsignet/upgrades_test.go index 53c27e3df..da26366b2 100644 --- a/app/upgrades/launch/upgrades_test.go +++ b/app/upgrades/launchsignet/upgrades_test.go @@ -1,4 +1,4 @@ -package launch_test +package launchsignet_test import ( "fmt" @@ -10,7 +10,7 @@ import ( "cosmossdk.io/x/upgrade" upgradetypes "cosmossdk.io/x/upgrade/types" "github.com/babylonlabs-io/babylon/app" - v1 "github.com/babylonlabs-io/babylon/app/upgrades/launch" + v1 "github.com/babylonlabs-io/babylon/app/upgrades/launchsignet" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" From 5b01140c34ad80173a10ebf6a59f47b5b51fb674 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 29 Jul 2024 21:52:42 -0300 Subject: [PATCH 05/89] fix: import cycle --- app/e2e_include_upgrades.go | 7 +++-- app/upgrades/launchsignet/upgrades.go | 3 +-- .../cmd/genhelpers/set_btc_headers.go | 26 +------------------ x/btclightclient/types/genesis.go | 18 +++++++++++++ 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/app/e2e_include_upgrades.go b/app/e2e_include_upgrades.go index 9d6af8d51..4f913c1ae 100644 --- a/app/e2e_include_upgrades.go +++ b/app/e2e_include_upgrades.go @@ -2,8 +2,11 @@ package app -import "github.com/babylonlabs-io/babylon/app/upgrades/vanilla" +import ( + "github.com/babylonlabs-io/babylon/app/upgrades/launchsignet" + "github.com/babylonlabs-io/babylon/app/upgrades/vanilla" +) func init() { - Upgrades = append(Upgrades, vanilla.Upgrade) + Upgrades = append(Upgrades, vanilla.Upgrade, launchsignet.Upgrade) } diff --git a/app/upgrades/launchsignet/upgrades.go b/app/upgrades/launchsignet/upgrades.go index 7a841b2ab..9765acdc0 100644 --- a/app/upgrades/launchsignet/upgrades.go +++ b/app/upgrades/launchsignet/upgrades.go @@ -20,7 +20,6 @@ import ( "github.com/babylonlabs-io/babylon/app/keepers" appparams "github.com/babylonlabs-io/babylon/app/params" "github.com/babylonlabs-io/babylon/app/upgrades" - "github.com/babylonlabs-io/babylon/cmd/babylond/cmd/genhelpers" btclightkeeper "github.com/babylonlabs-io/babylon/x/btclightclient/keeper" btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" ) @@ -68,7 +67,7 @@ func LoadBTCHeadersFromData() ([]*btclighttypes.BTCHeaderInfo, error) { } btcHeadersFilePath := filepath.Join(pwd, "data/btc_headers.json") - gs, err := genhelpers.LoadBtcLightGenStateFromFile(appparams.DefaultEncodingConfig().Codec, btcHeadersFilePath) + gs, err := btclighttypes.LoadBtcLightGenStateFromFile(appparams.DefaultEncodingConfig().Codec, btcHeadersFilePath) if err != nil { return nil, err } diff --git a/cmd/babylond/cmd/genhelpers/set_btc_headers.go b/cmd/babylond/cmd/genhelpers/set_btc_headers.go index 5ddfa3b36..7df48e4fd 100644 --- a/cmd/babylond/cmd/genhelpers/set_btc_headers.go +++ b/cmd/babylond/cmd/genhelpers/set_btc_headers.go @@ -2,12 +2,8 @@ package genhelpers import ( "fmt" - "os" - "path/filepath" - cmtos "github.com/cometbft/cometbft/libs/os" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" @@ -51,7 +47,7 @@ Possible content of 'btc_headers.json' is config := server.GetServerContextFromCmd(cmd).Config config.SetRoot(clientCtx.HomeDir) - inputBtcHeaders, err := LoadBtcLightGenStateFromFile(clientCtx.Codec, args[0]) + inputBtcHeaders, err := btclighttypes.LoadBtcLightGenStateFromFile(clientCtx.Codec, args[0]) if err != nil { return err } @@ -102,23 +98,3 @@ Possible content of 'btc_headers.json' is return cmd } - -func LoadBtcLightGenStateFromFile(cdc codec.Codec, inputFilePath string) (*btclighttypes.GenesisState, error) { - filePath := filepath.Clean(inputFilePath) - if !cmtos.FileExists(filePath) { - return nil, fmt.Errorf("input file %s does not exists", filePath) - } - - bz, err := os.ReadFile(filePath) - if err != nil { - return nil, err - } - - var genState btclighttypes.GenesisState - err = cdc.UnmarshalJSON(bz, &genState) - if err != nil { - return nil, err - } - - return &genState, nil -} diff --git a/x/btclightclient/types/genesis.go b/x/btclightclient/types/genesis.go index 13835fa2b..f8555fdcf 100644 --- a/x/btclightclient/types/genesis.go +++ b/x/btclightclient/types/genesis.go @@ -4,6 +4,8 @@ import ( "encoding/json" "errors" "fmt" + "os" + "path/filepath" bbn "github.com/babylonlabs-io/babylon/types" "github.com/btcsuite/btcd/chaincfg" @@ -86,3 +88,19 @@ func GenesisStateFromAppState(cdc codec.Codec, appState map[string]json.RawMessa return genesisState } + +func LoadBtcLightGenStateFromFile(cdc codec.Codec, inputFilePath string) (*GenesisState, error) { + filePath := filepath.Clean(inputFilePath) + bz, err := os.ReadFile(filePath) + if err != nil { + return nil, err + } + + var genState GenesisState + err = cdc.UnmarshalJSON(bz, &genState) + if err != nil { + return nil, err + } + + return &genState, nil +} From 85e027563b87e5cb4e8957df7af395064c626598 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 29 Jul 2024 22:04:12 -0300 Subject: [PATCH 06/89] chore: moved pkg name to signerlaunch --- app/e2e_include_upgrades.go | 4 ++-- app/upgrades/{launchsignet => signetlaunch}/README.md | 2 +- .../{launchsignet => signetlaunch}/data/btc_headers.json | 0 app/upgrades/{launchsignet => signetlaunch}/upgrades.go | 4 ++-- .../{launchsignet => signetlaunch}/upgrades_test.go | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) rename app/upgrades/{launchsignet => signetlaunch}/README.md (84%) rename app/upgrades/{launchsignet => signetlaunch}/data/btc_headers.json (100%) rename app/upgrades/{launchsignet => signetlaunch}/upgrades.go (97%) rename app/upgrades/{launchsignet => signetlaunch}/upgrades_test.go (93%) diff --git a/app/e2e_include_upgrades.go b/app/e2e_include_upgrades.go index 4f913c1ae..75e5d89de 100644 --- a/app/e2e_include_upgrades.go +++ b/app/e2e_include_upgrades.go @@ -3,10 +3,10 @@ package app import ( - "github.com/babylonlabs-io/babylon/app/upgrades/launchsignet" + "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" "github.com/babylonlabs-io/babylon/app/upgrades/vanilla" ) func init() { - Upgrades = append(Upgrades, vanilla.Upgrade, launchsignet.Upgrade) + Upgrades = append(Upgrades, vanilla.Upgrade, signetlaunch.Upgrade) } diff --git a/app/upgrades/launchsignet/README.md b/app/upgrades/signetlaunch/README.md similarity index 84% rename from app/upgrades/launchsignet/README.md rename to app/upgrades/signetlaunch/README.md index 39a776a61..26c89a050 100644 --- a/app/upgrades/launchsignet/README.md +++ b/app/upgrades/signetlaunch/README.md @@ -1,4 +1,4 @@ -# Launch Signet +# Signet Launch This folder contains a software upgrade for testing purposes. DO NOT USE IN PRODUCTION! diff --git a/app/upgrades/launchsignet/data/btc_headers.json b/app/upgrades/signetlaunch/data/btc_headers.json similarity index 100% rename from app/upgrades/launchsignet/data/btc_headers.json rename to app/upgrades/signetlaunch/data/btc_headers.json diff --git a/app/upgrades/launchsignet/upgrades.go b/app/upgrades/signetlaunch/upgrades.go similarity index 97% rename from app/upgrades/launchsignet/upgrades.go rename to app/upgrades/signetlaunch/upgrades.go index 9765acdc0..1981ab343 100644 --- a/app/upgrades/launchsignet/upgrades.go +++ b/app/upgrades/signetlaunch/upgrades.go @@ -1,7 +1,7 @@ // This code is only for testing purposes. // DO NOT USE IN PRODUCTION! -package launchsignet +package signetlaunch import ( "context" @@ -25,7 +25,7 @@ import ( ) var Upgrade = upgrades.Upgrade{ - UpgradeName: "launch-signet", + UpgradeName: "signet-launch", CreateUpgradeHandler: CreateUpgradeHandler, StoreUpgrades: store.StoreUpgrades{}, } diff --git a/app/upgrades/launchsignet/upgrades_test.go b/app/upgrades/signetlaunch/upgrades_test.go similarity index 93% rename from app/upgrades/launchsignet/upgrades_test.go rename to app/upgrades/signetlaunch/upgrades_test.go index da26366b2..d261ac607 100644 --- a/app/upgrades/launchsignet/upgrades_test.go +++ b/app/upgrades/signetlaunch/upgrades_test.go @@ -1,4 +1,4 @@ -package launchsignet_test +package signetlaunch_test import ( "fmt" @@ -10,7 +10,7 @@ import ( "cosmossdk.io/x/upgrade" upgradetypes "cosmossdk.io/x/upgrade/types" "github.com/babylonlabs-io/babylon/app" - v1 "github.com/babylonlabs-io/babylon/app/upgrades/launchsignet" + v1 "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" @@ -88,7 +88,7 @@ func (s *UpgradeTestSuite) TestUpgradePayments() { s.Equal(newHeadersLen, oldHeadersLen+lenHeadersInserted) // ensure the headers were inserted at the end - s.Equal(allBtcHeaders[len(allBtcHeaders)-lenHeadersInserted:], btcHeaders) + s.Equal(allBtcHeaders[newHeadersLen-lenHeadersInserted:], btcHeaders) }, }, } From c27b89e5572570db7c9ac190b1f13ad0526d555e Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 29 Jul 2024 22:11:05 -0300 Subject: [PATCH 07/89] fix: lint, panic if propLaunch fails --- app/upgrades/signetlaunch/upgrades.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/upgrades/signetlaunch/upgrades.go b/app/upgrades/signetlaunch/upgrades.go index 1981ab343..be8cdd3ca 100644 --- a/app/upgrades/signetlaunch/upgrades.go +++ b/app/upgrades/signetlaunch/upgrades.go @@ -40,7 +40,9 @@ func CreateUpgradeHandler( return func(context context.Context, _plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { ctx := sdk.UnwrapSDKContext(context) - propLaunch(ctx, &keepers.BTCLightClientKeeper) + if err := propLaunch(ctx, &keepers.BTCLightClientKeeper); err != nil { + panic(err) + } return mm.RunMigrations(ctx, cfg, fromVM) } From 02a4b51d98d0545406904e611f1e92eb04b95ab9 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 08:35:50 -0300 Subject: [PATCH 08/89] fixme: failing upgrade due to btc headers json not found --- .../chain/queries_btclightclient.go | 21 +++++++ test/e2e/configurer/config/constants.go | 5 +- test/e2e/e2e_test.go | 5 ++ ...software_upgrade_e2e_signet_launch_test.go | 62 +++++++++++++++++++ test/e2e/software_upgrade_e2e_test.go | 2 +- test/e2e/upgrades/signet-launch.json | 14 +++++ 6 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 test/e2e/configurer/chain/queries_btclightclient.go create mode 100644 test/e2e/software_upgrade_e2e_signet_launch_test.go create mode 100644 test/e2e/upgrades/signet-launch.json diff --git a/test/e2e/configurer/chain/queries_btclightclient.go b/test/e2e/configurer/chain/queries_btclightclient.go new file mode 100644 index 000000000..2c4cfb570 --- /dev/null +++ b/test/e2e/configurer/chain/queries_btclightclient.go @@ -0,0 +1,21 @@ +package chain + +import ( + "net/url" + + "github.com/stretchr/testify/require" + + "github.com/babylonlabs-io/babylon/test/e2e/util" + btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" +) + +func (n *NodeConfig) QueryBtcLightClientMainchain() []*btclighttypes.BTCHeaderInfoResponse { + bz, err := n.QueryGRPCGateway("/babylon/btclightclient/v1/mainchain", url.Values{}) + require.NoError(n.t, err) + + var resp btclighttypes.QueryMainChainResponse + err = util.Cdc.UnmarshalJSON(bz, &resp) + require.NoError(n.t, err) + + return resp.Headers +} diff --git a/test/e2e/configurer/config/constants.go b/test/e2e/configurer/config/constants.go index 72ee9e9b4..11a48e48d 100644 --- a/test/e2e/configurer/config/constants.go +++ b/test/e2e/configurer/config/constants.go @@ -15,6 +15,7 @@ const ( MaxRetries = 60 // PropSubmitBlocks estimated number of blocks it takes to submit for a proposal PropSubmitBlocks float32 = 1 - // VanillaUpgradeFilePath upgrade vanilla testing - VanillaUpgradeFilePath = "/upgrades/vanilla.json" + // UpgradeVanillaFilePath upgrade vanilla testing + UpgradeVanillaFilePath = "/upgrades/vanilla.json" + UpgradeSignetLaunchFilePath = "/upgrades/signet-launch.json" ) diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index cc78d6b15..801e6d511 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -40,3 +40,8 @@ func TestBTCStakingTestSuite(t *testing.T) { func TestSoftwareUpgradeTestSuite(t *testing.T) { suite.Run(t, new(SoftwareUpgradeVanillaTestSuite)) } + +// TestSoftwareUpgradeSignetLaunchTestSuite tests software upgrade of signet launch end-to-end +func TestSoftwareUpgradeSignetLaunchTestSuite(t *testing.T) { + suite.Run(t, new(SoftwareUpgradeSignetLaunchTestSuite)) +} diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go new file mode 100644 index 000000000..c18b0786c --- /dev/null +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -0,0 +1,62 @@ +package e2e + +import ( + "github.com/stretchr/testify/suite" + + v1 "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" + "github.com/babylonlabs-io/babylon/test/e2e/configurer" + "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" +) + +type SoftwareUpgradeSignetLaunchTestSuite struct { + suite.Suite + + configurer configurer.Configurer +} + +func (s *SoftwareUpgradeSignetLaunchTestSuite) SetupSuite() { + s.T().Log("setting up e2e integration test suite...") + var err error + + s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.UpgradeSignetLaunchFilePath) + s.NoError(err) + err = s.configurer.ConfigureChains() + s.NoError(err) + err = s.configurer.RunSetup() // upgrade happens at the setup of configurer. + s.NoError(err) +} + +func (s *SoftwareUpgradeSignetLaunchTestSuite) TearDownSuite() { + err := s.configurer.ClearResources() + s.Require().NoError(err) +} + +// TestUpgradeSignetLaunch Checks if the BTC Headers were inserted. +func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() { + // chain is already upgraded, only checks for differences in state are expected + chainA := s.configurer.GetChainConfig(0) + chainA.WaitUntilHeight(30) // five blocks more than upgrade + + n, err := chainA.GetDefaultNode() + s.NoError(err) + + expectedUpgradeHeight := int64(25) + + // makes sure that the upgrade was actually executed + resp := n.QueryAppliedPlan("vanilla") + s.EqualValues(expectedUpgradeHeight, resp.Height, "the plan should be applied at the height 25") + + allBtcHeaders := n.QueryBtcLightClientMainchain() + + btcHeadersFromFile, err := v1.LoadBTCHeadersFromData() + s.NoError(err) + + lenHeadersInserted := len(btcHeadersFromFile) + oldHeadersLen := 1 // only block zero is set by default in e2e test + + newHeadersLen := len(allBtcHeaders) + s.Equal(newHeadersLen, oldHeadersLen+lenHeadersInserted) + + // ensure the headers were inserted at the end + s.Equal(allBtcHeaders[newHeadersLen-lenHeadersInserted:], btcHeadersFromFile) +} diff --git a/test/e2e/software_upgrade_e2e_test.go b/test/e2e/software_upgrade_e2e_test.go index 3cac9f9c9..0173d9e51 100644 --- a/test/e2e/software_upgrade_e2e_test.go +++ b/test/e2e/software_upgrade_e2e_test.go @@ -17,7 +17,7 @@ func (s *SoftwareUpgradeVanillaTestSuite) SetupSuite() { s.T().Log("setting up e2e integration test suite...") var err error - s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.VanillaUpgradeFilePath) + s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.UpgradeVanillaFilePath) s.NoError(err) err = s.configurer.ConfigureChains() s.NoError(err) diff --git a/test/e2e/upgrades/signet-launch.json b/test/e2e/upgrades/signet-launch.json new file mode 100644 index 000000000..de4638b31 --- /dev/null +++ b/test/e2e/upgrades/signet-launch.json @@ -0,0 +1,14 @@ +{ + "title": "any title", + "summary": "any summary", + "messages": [ + { + "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + "authority": "bbn10d07y265gmmuvt4z0w9aw880jnsr700jduz5f2", + "plan": { "name": "signet-launch", "info": "Msg info", "height": 25 } + } + ], + "deposit": "500000000ubbn", + "initial_deposit": "500000000ubbn", + "initialDeposit": "500000000ubbn" +} \ No newline at end of file From 416517394b3da8f748cd285af6cca0922c67d896 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 08:42:43 -0300 Subject: [PATCH 09/89] chore: update to use v09 before upgrade --- contrib/images/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/images/Makefile b/contrib/images/Makefile index c0afef21b..beef16916 100644 --- a/contrib/images/Makefile +++ b/contrib/images/Makefile @@ -1,6 +1,6 @@ RELAYER_TAG := $(shell grep '^ENV RELAYER_TAG' cosmos-relayer/Dockerfile | cut -f3 -d\ ) BABYLON_FULL_PATH := $(shell git rev-parse --show-toplevel) -BABYLON_VERSION_BEFORE_UPGRADE ?= 5f8af8ced17d24f3f0c6172293cd37fb3d055807 +BABYLON_VERSION_BEFORE_UPGRADE ?= v0.9.0 all: babylond cosmos-relayer From ec9e59e980a10beeb59dc89ba695a1b13053c3af Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 08:54:38 -0300 Subject: [PATCH 10/89] chore: removed fetch origin --- contrib/images/babylond/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/images/babylond/Dockerfile b/contrib/images/babylond/Dockerfile index 50f7857b8..01118ba38 100644 --- a/contrib/images/babylond/Dockerfile +++ b/contrib/images/babylond/Dockerfile @@ -20,7 +20,6 @@ RUN go mod download COPY ./ /go/src/github.com/babylonlabs-io/babylon/ # If version is set, then checkout this version RUN if [ -n "${VERSION}" ]; then \ - git fetch origin ${VERSION}; \ git checkout -f ${VERSION}; \ fi From 678510601209463453189b17327c8ae4ce0171fe Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 09:04:01 -0300 Subject: [PATCH 11/89] fix: fetch all --- contrib/images/babylond/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/images/babylond/Dockerfile b/contrib/images/babylond/Dockerfile index 01118ba38..344877e0b 100644 --- a/contrib/images/babylond/Dockerfile +++ b/contrib/images/babylond/Dockerfile @@ -20,6 +20,7 @@ RUN go mod download COPY ./ /go/src/github.com/babylonlabs-io/babylon/ # If version is set, then checkout this version RUN if [ -n "${VERSION}" ]; then \ + git fetch --all; \ git checkout -f ${VERSION}; \ fi From d1775a9ccfb343e1794141a8b4f698de069a0b0f Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 10:30:45 -0300 Subject: [PATCH 12/89] chore: add identifier name to networks --- test/e2e/configurer/factory.go | 18 ++++++++++++------ test/e2e/containers/containers.go | 9 ++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/test/e2e/configurer/factory.go b/test/e2e/configurer/factory.go index 985216cdd..df41dc9a2 100644 --- a/test/e2e/configurer/factory.go +++ b/test/e2e/configurer/factory.go @@ -114,7 +114,8 @@ var ( // TODO currently only one configuration is available. Consider testing upgrades // when necessary func NewBTCTimestampingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, false, false) + identifier := t.Name() + containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false) if err != nil { return nil, err } @@ -130,7 +131,8 @@ func NewBTCTimestampingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configu } func NewIBCTransferConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, false, false) + identifier := t.Name() + containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false) if err != nil { return nil, err } @@ -147,7 +149,8 @@ func NewIBCTransferConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, // NewBTCTimestampingPhase2Configurer returns a new Configurer for BTC timestamping service (phase 2). func NewBTCTimestampingPhase2Configurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, false, false) + identifier := t.Name() + containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false) if err != nil { return nil, err } @@ -164,7 +167,8 @@ func NewBTCTimestampingPhase2Configurer(t *testing.T, isDebugLogEnabled bool) (C // NewBTCTimestampingPhase2RlyConfigurer returns a new Configurer for BTC timestamping service (phase 2), using the Go relayer (rly). func NewBTCTimestampingPhase2RlyConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, true, false) + identifier := t.Name() + containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, true, false) if err != nil { return nil, err } @@ -181,7 +185,8 @@ func NewBTCTimestampingPhase2RlyConfigurer(t *testing.T, isDebugLogEnabled bool) // NewBTCStakingConfigurer returns a new Configurer for BTC staking service func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, false, false) + identifier := t.Name() + containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false) if err != nil { return nil, err } @@ -198,7 +203,8 @@ func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, // NewSoftwareUpgradeConfigurer returns a new Configurer for Software Upgrade testing func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradePath string) (Configurer, error) { - containerManager, err := containers.NewManager(isDebugLogEnabled, false, true) + identifier := t.Name() + containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, true) if err != nil { return nil, err } diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 2de3bc413..88f55566d 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -36,15 +36,17 @@ type Manager struct { network *dockertest.Network resources map[string]*dockertest.Resource isDebugLogEnabled bool + identifier string } // NewManager creates a new Manager instance and initializes // all Docker specific utilities. Returns an error if initialization fails. -func NewManager(isDebugLogEnabled bool, isCosmosRelayer, isUpgrade bool) (docker *Manager, err error) { +func NewManager(identifier string, isDebugLogEnabled bool, isCosmosRelayer, isUpgrade bool) (docker *Manager, err error) { docker = &Manager{ ImageConfig: NewImageConfig(isCosmosRelayer, isUpgrade), resources: make(map[string]*dockertest.Resource), isDebugLogEnabled: isDebugLogEnabled, + identifier: identifier, } docker.pool, err = dockertest.NewPool("") if err != nil { @@ -380,3 +382,8 @@ func (m *Manager) RunChainInitResource(chainId string, chainVotingPeriod, chainE } return initResource, nil } + +// NetworkName returns the network name concatenated with the identifier name +func (m *Manager) NetworkName() string { + return fmt.Sprintf("bbn-testnet-%s", m.identifier) +} From 3d58d6db983957755fa6f1836d9b645011e79843 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 11:12:19 -0300 Subject: [PATCH 13/89] chore: moved new btc headers to str instead of json --- .../btc_headers.json => data_btc_headers.go} | 6 ++++-- app/upgrades/signetlaunch/upgrades.go | 16 +++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) rename app/upgrades/signetlaunch/{data/btc_headers.json => data_btc_headers.go} (98%) diff --git a/app/upgrades/signetlaunch/data/btc_headers.json b/app/upgrades/signetlaunch/data_btc_headers.go similarity index 98% rename from app/upgrades/signetlaunch/data/btc_headers.json rename to app/upgrades/signetlaunch/data_btc_headers.go index cd74a8382..9c0ebb513 100644 --- a/app/upgrades/signetlaunch/data/btc_headers.json +++ b/app/upgrades/signetlaunch/data_btc_headers.go @@ -1,4 +1,6 @@ -{ +package signetlaunch + +const NewBtcHeadersStr = `{ "btc_headers": [ { "header": "0000002095156a30ef4e6c9764c0ce83fac51a37365b2092bd39bdbfd038f5b98f00000077f14ee2b34b7dcbb7e3fc624184b919b74cd047837728593140ee21e59cc5bee4c9a766644d011e4e202800", @@ -85,4 +87,4 @@ "work": "180357618" } ] -} \ No newline at end of file +}` diff --git a/app/upgrades/signetlaunch/upgrades.go b/app/upgrades/signetlaunch/upgrades.go index be8cdd3ca..3c5dc4794 100644 --- a/app/upgrades/signetlaunch/upgrades.go +++ b/app/upgrades/signetlaunch/upgrades.go @@ -4,11 +4,10 @@ package signetlaunch import ( + "bytes" "context" "errors" "fmt" - "os" - "path/filepath" "sort" store "cosmossdk.io/store/types" @@ -61,18 +60,17 @@ func propLaunch( return insertBtcHeaders(ctx, btcLigthK, newHeaders) } -// LoadBTCHeadersFromData returns the BTC headers load from the data/btc_headers.json path. +// LoadBTCHeadersFromData returns the BTC headers load from the json string with the headers inside of it. func LoadBTCHeadersFromData() ([]*btclighttypes.BTCHeaderInfo, error) { - pwd, err := os.Getwd() - if err != nil { - return nil, err - } + cdc := appparams.DefaultEncodingConfig().Codec + buff := bytes.NewBufferString(NewBtcHeadersStr) - btcHeadersFilePath := filepath.Join(pwd, "data/btc_headers.json") - gs, err := btclighttypes.LoadBtcLightGenStateFromFile(appparams.DefaultEncodingConfig().Codec, btcHeadersFilePath) + var gs btclighttypes.GenesisState + err := cdc.UnmarshalJSON(buff.Bytes(), &gs) if err != nil { return nil, err } + return gs.BtcHeaders, nil } From 6f92d842db4fbea7c1a7c929084a7beb5de7e04e Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 12:04:46 -0300 Subject: [PATCH 14/89] chore: update vanilla file name and check the values are equal in btc headers --- test/e2e/software_upgrade_e2e_signet_launch_test.go | 4 ++-- ...grade_e2e_test.go => software_upgrade_e2e_vanilla_test.go} | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) rename test/e2e/{software_upgrade_e2e_test.go => software_upgrade_e2e_vanilla_test.go} (92%) diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go index c18b0786c..d0829bf6b 100644 --- a/test/e2e/software_upgrade_e2e_signet_launch_test.go +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -43,7 +43,7 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() { expectedUpgradeHeight := int64(25) // makes sure that the upgrade was actually executed - resp := n.QueryAppliedPlan("vanilla") + resp := n.QueryAppliedPlan(v1.Upgrade.UpgradeName) s.EqualValues(expectedUpgradeHeight, resp.Height, "the plan should be applied at the height 25") allBtcHeaders := n.QueryBtcLightClientMainchain() @@ -58,5 +58,5 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() { s.Equal(newHeadersLen, oldHeadersLen+lenHeadersInserted) // ensure the headers were inserted at the end - s.Equal(allBtcHeaders[newHeadersLen-lenHeadersInserted:], btcHeadersFromFile) + s.EqualValues(allBtcHeaders[newHeadersLen-lenHeadersInserted:], btcHeadersFromFile) } diff --git a/test/e2e/software_upgrade_e2e_test.go b/test/e2e/software_upgrade_e2e_vanilla_test.go similarity index 92% rename from test/e2e/software_upgrade_e2e_test.go rename to test/e2e/software_upgrade_e2e_vanilla_test.go index 0173d9e51..9a8570b6d 100644 --- a/test/e2e/software_upgrade_e2e_test.go +++ b/test/e2e/software_upgrade_e2e_vanilla_test.go @@ -3,6 +3,7 @@ package e2e import ( "github.com/stretchr/testify/suite" + v1 "github.com/babylonlabs-io/babylon/app/upgrades/vanilla" "github.com/babylonlabs-io/babylon/test/e2e/configurer" "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" ) @@ -42,7 +43,7 @@ func (s *SoftwareUpgradeVanillaTestSuite) TestUpgradeVanilla() { expectedUpgradeHeight := int64(25) // makes sure that the upgrade was actually executed - resp := n.QueryAppliedPlan("vanilla") + resp := n.QueryAppliedPlan(v1.Upgrade.UpgradeName) s.EqualValues(expectedUpgradeHeight, resp.Height, "the plan should be applied at the height 25") fps := n.QueryFinalityProviders() From 4e115b413d85c8ec20094112ef6d59d553c94d04 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 12:13:21 -0300 Subject: [PATCH 15/89] fix: comparison with inserted values --- ...software_upgrade_e2e_signet_launch_test.go | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go index d0829bf6b..7cb1c8644 100644 --- a/test/e2e/software_upgrade_e2e_signet_launch_test.go +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -5,6 +5,7 @@ import ( v1 "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" "github.com/babylonlabs-io/babylon/test/e2e/configurer" + "github.com/babylonlabs-io/babylon/test/e2e/configurer/chain" "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" ) @@ -46,17 +47,23 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() { resp := n.QueryAppliedPlan(v1.Upgrade.UpgradeName) s.EqualValues(expectedUpgradeHeight, resp.Height, "the plan should be applied at the height 25") - allBtcHeaders := n.QueryBtcLightClientMainchain() - - btcHeadersFromFile, err := v1.LoadBTCHeadersFromData() + btcHeadersInserted, err := v1.LoadBTCHeadersFromData() s.NoError(err) - lenHeadersInserted := len(btcHeadersFromFile) - oldHeadersLen := 1 // only block zero is set by default in e2e test + lenHeadersInserted := len(btcHeadersInserted) + oldHeadersStoredLen := 1 // only block zero is set by default in genesis for e2e test - newHeadersLen := len(allBtcHeaders) - s.Equal(newHeadersLen, oldHeadersLen+lenHeadersInserted) + storedBtcHeadersResp := n.QueryBtcLightClientMainchain() + newHeadersLen := len(storedBtcHeadersResp) + s.Equal(newHeadersLen, oldHeadersStoredLen+lenHeadersInserted) // ensure the headers were inserted at the end - s.EqualValues(allBtcHeaders[newHeadersLen-lenHeadersInserted:], btcHeadersFromFile) + for i := 0; i < newHeadersLen-lenHeadersInserted; i++ { + headerInserted := btcHeadersInserted[i] + headerStoredResp := storedBtcHeadersResp[oldHeadersStoredLen+i] + + headerStored, err := chain.ParseBTCHeaderInfoResponseToInfo(headerStoredResp) + s.NoError(err) + s.EqualValues(headerInserted, headerStored) + } } From a8cbda5b6b8ff300da404de7261483dc1791f9cf Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 12:15:21 -0300 Subject: [PATCH 16/89] fix: compare the response of btc headers --- test/e2e/software_upgrade_e2e_signet_launch_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go index 7cb1c8644..76ae3a5a9 100644 --- a/test/e2e/software_upgrade_e2e_signet_launch_test.go +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -5,7 +5,6 @@ import ( v1 "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" "github.com/babylonlabs-io/babylon/test/e2e/configurer" - "github.com/babylonlabs-io/babylon/test/e2e/configurer/chain" "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" ) @@ -62,8 +61,6 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() { headerInserted := btcHeadersInserted[i] headerStoredResp := storedBtcHeadersResp[oldHeadersStoredLen+i] - headerStored, err := chain.ParseBTCHeaderInfoResponseToInfo(headerStoredResp) - s.NoError(err) - s.EqualValues(headerInserted, headerStored) + s.EqualValues(headerInserted.ToResponse(), headerStoredResp) } } From 7fdc39e2e496aea05bae5347295dc860b7310e38 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 12:20:45 -0300 Subject: [PATCH 17/89] fix: reverse from chain stored --- test/e2e/software_upgrade_e2e_signet_launch_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go index 76ae3a5a9..bffbeaa70 100644 --- a/test/e2e/software_upgrade_e2e_signet_launch_test.go +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -53,14 +53,14 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() { oldHeadersStoredLen := 1 // only block zero is set by default in genesis for e2e test storedBtcHeadersResp := n.QueryBtcLightClientMainchain() - newHeadersLen := len(storedBtcHeadersResp) - s.Equal(newHeadersLen, oldHeadersStoredLen+lenHeadersInserted) + storedHeadersLen := len(storedBtcHeadersResp) + s.Equal(storedHeadersLen, oldHeadersStoredLen+lenHeadersInserted) // ensure the headers were inserted at the end - for i := 0; i < newHeadersLen-lenHeadersInserted; i++ { - headerInserted := btcHeadersInserted[i] - headerStoredResp := storedBtcHeadersResp[oldHeadersStoredLen+i] + for i := 0; i < storedHeadersLen-lenHeadersInserted; i++ { + headerInsertedResp := btcHeadersInserted[i].ToResponse() + headerStoredResp := storedBtcHeadersResp[storedHeadersLen-(oldHeadersStoredLen+i)] // reverse - s.EqualValues(headerInserted.ToResponse(), headerStoredResp) + s.EqualValues(headerInsertedResp, headerStoredResp) } } From f81da6ad6ab749561259bd747488835bc02f5e90 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 30 Jul 2024 13:47:50 -0300 Subject: [PATCH 18/89] fix: reverse index read from chain stored --- test/e2e/software_upgrade_e2e_signet_launch_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go index bffbeaa70..5d2ffd1b5 100644 --- a/test/e2e/software_upgrade_e2e_signet_launch_test.go +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -57,9 +57,10 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() { s.Equal(storedHeadersLen, oldHeadersStoredLen+lenHeadersInserted) // ensure the headers were inserted at the end - for i := 0; i < storedHeadersLen-lenHeadersInserted; i++ { + for i := 0; i < lenHeadersInserted; i++ { headerInsertedResp := btcHeadersInserted[i].ToResponse() - headerStoredResp := storedBtcHeadersResp[storedHeadersLen-(oldHeadersStoredLen+i)] // reverse + reversedStoredIndex := storedHeadersLen - (oldHeadersStoredLen + i + 1) + headerStoredResp := storedBtcHeadersResp[reversedStoredIndex] // reverse reading s.EqualValues(headerInsertedResp, headerStoredResp) } From a56f49910f36c876222eae82b98f0921cbcffb92 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 1 Aug 2024 15:14:26 -0300 Subject: [PATCH 19/89] fix: run migrations before prop updates --- app/upgrades/signetlaunch/upgrades.go | 7 ++++++- app/upgrades/vanilla/upgrades.go | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/upgrades/signetlaunch/upgrades.go b/app/upgrades/signetlaunch/upgrades.go index 3c5dc4794..4a080fdf0 100644 --- a/app/upgrades/signetlaunch/upgrades.go +++ b/app/upgrades/signetlaunch/upgrades.go @@ -39,11 +39,16 @@ func CreateUpgradeHandler( 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 mm.RunMigrations(ctx, cfg, fromVM) + return migrations, nil } } diff --git a/app/upgrades/vanilla/upgrades.go b/app/upgrades/vanilla/upgrades.go index cb01322e5..99522243e 100644 --- a/app/upgrades/vanilla/upgrades.go +++ b/app/upgrades/vanilla/upgrades.go @@ -32,12 +32,16 @@ func CreateUpgradeHandler( 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 + } + propVanilla(ctx, &keepers.AccountKeeper, &keepers.BTCStakingKeeper) - return mm.RunMigrations(ctx, cfg, fromVM) + return migrations, nil } } From 801ac1f20eab6f6fc0ff85cc8c52ac8cd2d15214 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 1 Aug 2024 15:31:33 -0300 Subject: [PATCH 20/89] chore: rollback licence babylon labs --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index d08b6069f..dc41cf54b 100644 --- a/LICENSE +++ b/LICENSE @@ -8,10 +8,10 @@ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. Parameters -Licensor: BabylonLabs, Ltd. +Licensor: Babylon Labs, Ltd. Licensed Work: Babylon - The Licensed Work is (c) 2023 BabylonLabs, Ltd. + The Licensed Work is (c) 2023 Babylon Labs, Ltd. Additional Use Grant: None. From 3c9ae6132c910d3ffed4c9d732bbcb68d0958ea3 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 1 Aug 2024 17:18:15 -0300 Subject: [PATCH 21/89] fix: make sure the headers form a correct chain of btc blocks in the upgrade --- app/upgrades/signetlaunch/data_btc_headers.go | 118 +++++++++--------- app/upgrades/signetlaunch/upgrades.go | 22 ++-- app/upgrades/signetlaunch/upgrades_test.go | 34 ++++- 3 files changed, 106 insertions(+), 68 deletions(-) diff --git a/app/upgrades/signetlaunch/data_btc_headers.go b/app/upgrades/signetlaunch/data_btc_headers.go index 9c0ebb513..2c5479fb9 100644 --- a/app/upgrades/signetlaunch/data_btc_headers.go +++ b/app/upgrades/signetlaunch/data_btc_headers.go @@ -3,88 +3,94 @@ package signetlaunch const NewBtcHeadersStr = `{ "btc_headers": [ { - "header": "0000002095156a30ef4e6c9764c0ce83fac51a37365b2092bd39bdbfd038f5b98f00000077f14ee2b34b7dcbb7e3fc624184b919b74cd047837728593140ee21e59cc5bee4c9a766644d011e4e202800", - "hash": "0000010a767aed4930b7cf4aa0f90b4cc23d8e5375142c0a626aba09ff411f06", - "height": 206500, - "work": "180357618" + "header": "00000020f61eee3b63a380a477a063af32b2bbc97c9ff9f01f2c4225e973988108000000f575c83235984e7dc4afc1f30944c170462e84437ab6f2d52e16878a79e4678bd1914d5fae77031eccf40700", + "hash": "00000086d6b2636cb2a392d45edc4ec544a10024d30141c9adf4bfd9de533b53", + "height": 1, + "work": "77414720" }, { - "header": "00000020061f41ff09ba6a620a2c1475538e3dc24c0bf9a04acfb73049ed7a760a0100004a7b4cec7be4c56a3dfdb833e94a5ff5ce4bdf5b5b0a599a39ef717fffe914b4ecd0a766644d011e822f6102", - "hash": "0000000a36d6c67675cbbbf1f8dc5cafd5def468b5b5e063768ddc3147e065d7", - "height": 206501, - "work": "180357618" + "header": "00000020533b53ded9bff4adc94101d32400a144c54edc5ed492a3b26c63b2d686000000b38fef50592017cfafbcab88eb3d9cf50b2c801711cad8299495d26df5e54812e7914d5fae77031ecfdd0b00", + "hash": "00000032bb881de703dcc968e8258080c7ed4a2933e3a35888fa0b2f75f36029", + "height": 2, + "work": "77414720" }, { - "header": "00000020d765e04731dc8d7663e0b5b568f4ded5af5cdcf8f1bbcb7576c6d6360a000000fb1a404fe53effdb9c0769966614fbe7cd7d7d537068339fc38a4c41e14ed6b1bfd1a766644d011eddc8aa00", - "hash": "0000008a5a47ffe1e621ee2d4c8f4baeef953da8e915d6837ccbaa7a7b877d2c", - "height": 206502, - "work": "180357618" + "header": "000000202960f3752f0bfa8858a3e333294aedc7808025e868c9dc03e71d88bb320000007765fcd3d5b4966beb338bba2675dc2cf2ad28d4ad1d83bdb6f286e7e27ac1f807924d5fae77031e81d60b00", + "hash": "000000e8daac2a2e973ecaab46dc948181c638adecf5ae0fd5d3e13aa14364b0", + "height": 3, + "work": "77414720" }, { - "header": "000000202c7d877b7aaacb7c83d615e9a83d95efae4b8f4c2dee21e6e1ff475a8a000000aa2d38699ab5195fb8d75512e639f3467aacb0346bf5478d529c969c6aa398fb64d3a766644d011ee2dc5f01", - "hash": "000000c7b179e7283c8641d1d1ff6a0b202213a19463490a79163aef0ccfad1e", - "height": 206503, - "work": "180357618" + "header": "00000020b06443a13ae1d3d50faef5ecad38c6818194dc46abca3e972e2aacdae800000069a5829097e80fee00ac49a56ea9f82d741a6af84d32b3bc455cf31871e2a8ac27924d5fae77031e9c910500", + "hash": "00000194763f1233e40afd5f6eb2e64abd2e5e158a4139198a224f8a7503d47e", + "height": 4, + "work": "77414720" }, { - "header": "000000201eadcf0cef3a16790a496394a11322200b6affd1d141863c28e779b1c70000006b58a84c6d1ba0c1841592fd5855f54e354e2b2a4d9467f57c9a22cb7b8a6b4984d3a766644d011e50d96c01", - "hash": "000000fc83896a94e89aae093c648bac3841de08a0dbe4ab1719db22796442b8", - "height": 206504, - "work": "180357618" + "header": "000000207ed403758a4f228a1939418a155e2ebd4ae6b26e5ffd0ae433123f7694010000542e80b609c5bc58af5bdf492e26d4f60cd43a3966c2e063c50444c29b3757a636924d5fae77031ee8601d00", + "hash": "000003776c984edd753b876f0e70d08450f92dd76a768df03d2c42d1880aea5b", + "height": 5, + "work": "77414720" }, { - "header": "00000020b842647922db1917abe4dba008de4138ac8b643c09ae9ae8946a8983fc0000001e2eafc39aed81b433b9dc5fbf4916460f414c9333ace37bb99a300950ff76241fd5a766644d011ecffa8c00", - "hash": "000000a839a452cfa49121973e1ecd17838b74fd3238abfc5e28a8d04fa76fd9", - "height": 206505, - "work": "180357618" + "header": "000000205bea0a88d1422c3df08d766ad72df95084d0700e6f873b75dd4e986c7703000002b57516d33ed60c2bdd9f93d6d5614083324c837e68e5ba6e04287a7285633585924d5fae77031ed1719600", + "hash": "000001b62ff822d0b1c68e231670eba2cf8d494075f9616447194b370db6f3da", + "height": 6, + "work": "77414720" }, { - "header": "00000020d96fa74fd0a8285efcab3832fd748b8317cd1e3e972191a4cf52a439a800000092e19ee24b41b4debca252714de700a8573c610ad277866abd238ae527d899d40dd6a766644d011e053a5c00", - "hash": "000000edb41b0c424a7ffbbaf5704daf494d9209013ca10b3f76d66610d77d99", - "height": 206506, - "work": "180357618" + "header": "00000020daf3b60d374b19476461f97540498dcfa2eb7016238ec6b1d022f82fb60100007a7ae65b53cb988c2ec92d2384996713821d5645ffe61c9acea60da75cd5edfa1a944d5fae77031e9dbb0500", + "hash": "000000b6f018c5b53240616c7868eab7e1338de4200ec25b65a5e1c2f3c57c45", + "height": 7, + "work": "77414720" }, { - "header": "00000020997dd71066d6763f0ba13c0109924d49af4d70f5bafb7f4a420c1bb4ed000000fa2603a7097ff5d5fb2ca0b5dc33fce8ae8cdc44916b736cabdeef8abab05a7b38d6a766644d011ee7bbe900", - "hash": "0000006516e2ff853d1fc48e476df001420e7e5b740ea178b7edc5f557e27c58", - "height": 206507, - "work": "180357618" + "header": "00000020457cc5f3c2e1a5655bc20e20e48d33e1b7ea68786c614032b5c518f0b6000000541f36942d82c6e7248275ff15c8933487fbe1819c67a9ecc0f4b70bb7e6cf672a944d5fae77031e8f398600", + "hash": "000002213230ed813e42076f753f666244db421b3e36a3a3ba31384feb61eba2", + "height": 8, + "work": "77414720" }, { - "header": "00000020587ce257f5c5edb778a10e745b7e0e4201f06d478ec41f3d85ffe21665000000cde05d3c4355c5aef220d5b16ffb8339ae979c513f8af0bc5c74d21ac8a4fd2e45d7a766644d011eabacbe00", - "hash": "0000001ec310dc0a5113ae10f00d944f01562c0a4c50c8ee41ff00b164cb81cc", - "height": 206508, - "work": "180357618" + "header": "00000020a2eb61eb4f3831baa3a3363e1b42db4462663f756f07423e81ed30322102000077224de7dea0f8d0ec22b1d2e2e255f0a987b96fe7200e1a2e6373f48a2f5b7894954d5fae77031e36867e00", + "hash": "000001e163d0a8e294c3406a713ba4363f422f1322a1d6ab6de4e54b51e868a8", + "height": 9, + "work": "77414720" }, { - "header": "00000020cc81cb64b100ff41eec8504c0a2c56014f940df010ae13510adc10c31e0000006433905cd152679dc2620d09a44203589743d88c181a0342811225ff823b484f85d8a766644d011e077d7300", - "hash": "000000e04fd41669fac0a6fbf595e795d841ca1f1f3df82410b7be8d8956c0e0", - "height": 206509, - "work": "180357618" + "header": "00000020a868e8514be5e46dabd6a122132f423f36a43b716a40c394e2a8d063e1010000f4c6c717e99d800c699c25a2006a75a0c5c09f432a936f385e6fce139cdbd1a5e9964d5fae77031e7d026e00", + "hash": "000001418e9af8310ef3644093dbc4a8ad9edb0c9ac80397f3479ad1729d965b", + "height": 10, + "work": "77414720" }, { - "header": "00000020e0c056898dbeb71024f83d1f1fca41d895e795f5fba6c0fa6916d44fe0000000dfb1582ec3ecf5c35a7ca4a75624d17517373371923a19dc1729f62f24402f0371daa766644d011e605fcd00", - "hash": "000000dc9ea403aadca79175d75ab6a09f21178955e1aa92ad134d1f35639317", - "height": 206510, - "work": "180357618" + "header": "000000205b969d72d19a47f39703c89a0cdb9eada8c4db934064f30e31f89a8e41010000949eef89068ffc76bf4dca6762e26581d410d0df40edf147d4ffdc6dea404a1512984d5fae77031ee67c1200", + "hash": "0000034cdfe52a76f70f137be5b44dd2d10b305d03a42229767ec5b524d81094", + "height": 11, + "work": "77414720" }, { - "header": "00000020179363351f4d13ad92aae1558917219fa0b65ad77591a7dcaa03a49edc0000007b03a2a905ac70c86e3568978c8a1e5f4aa720999d3dbd2e2bdfffbc3b7ecf6306dba766644d011ed6383600", - "hash": "0000008cb36ab72c793033a25ccb5ea266a63c6d8a3a8774db9574bd2f099a26", - "height": 206511, - "work": "180357618" + "header": "000000209410d824b5c57e762922a4035d300bd1d24db4e57b130ff7762ae5df4c030000532299955b2dc6bd7c13c267d3c0990fefdf7aec3bcbab5b2c85d0d36316f93644984d5fae77031ecdea1600", + "hash": "000000375d267acf5e788946bd885735d215a98e13eb1b1dcb79403a4549f609", + "height": 12, + "work": "77414720" }, { - "header": "00000020269a092fbd7495db74873a8a6d3ca666a25ecb5ca23330792cb76ab38c000000d6ad13ceaa5c27b1e1e2d68b0080cc40b82b44faf895e3f819edfae1709aa74587dba766644d011e93fc8a00", - "hash": "000000e698603e02a0ae61186f6b6294f8f58732bcfb1bf7c5c8cc8c25b17134", - "height": 206512, - "work": "180357618" + "header": "0000002009f649453a4079cb1d1beb138ea915d2355788bd4689785ecf7a265d3700000010bd26b43a88350e614736674431e62cc7c77dc577d07edd80620a02339d5fab82984d5fae77031efe682400", + "hash": "000000aa98270ecd860f5b0f34eed287b66a24b80738eeb9b5e7a65791ffb935", + "height": 13, + "work": "77414720" }, { - "header": "000000203471b1258cccc8c5f71bfbbc3287f5f894626b6f1861aea0023e6098e60000002d05f3d038ee2535da13f928afa100e9dac12598c11afc19b0e952a22bc924d1ecdba766644d011e5eb27d00", - "hash": "0000001ea82bcd9bb5ada7c186a3f1b02413fd0e5d873e44825ca628e5511496", - "height": 206513, - "work": "180357618" + "header": "0000002035b9ff9157a6e7b5b9ee3807b8246ab687d2ee340f5b0f86cd0e2798aa00000028ef48260b3c0d45bbe5321335b05dde8fcb130e063202457884585298b8a5dde4984d5fae77031ec0a08600", + "hash": "00000150de45736bb5158f63a94b9570540d68871eaa8fa03141d16ffb2f1086", + "height": 14, + "work": "77414720" + }, + { + "header": "0000002086102ffb6fd14131a08faa1e87680d5470954ba9638f15b56b7345de500100009f423c63aa6d39330082b58808013a85af5a7f338a7a3587f0a85b587665e6174e9a4d5fae77031e79353a00", + "hash": "0000013aadf507653857ebf15a210e31aa7be6d02d1608602a1d4906a08cf528", + "height": 15, + "work": "77414720" } ] }` diff --git a/app/upgrades/signetlaunch/upgrades.go b/app/upgrades/signetlaunch/upgrades.go index 4a080fdf0..8d6565c41 100644 --- a/app/upgrades/signetlaunch/upgrades.go +++ b/app/upgrades/signetlaunch/upgrades.go @@ -19,6 +19,7 @@ import ( "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" ) @@ -82,23 +83,30 @@ func LoadBTCHeadersFromData() ([]*btclighttypes.BTCHeaderInfo, error) { func insertBtcHeaders( ctx sdk.Context, k *btclightkeeper.Keeper, - headers []*btclighttypes.BTCHeaderInfo, + btcHeaders []*btclighttypes.BTCHeaderInfo, ) error { - if len(headers) == 0 { + if len(btcHeaders) == 0 { return errors.New("no headers to insert") } // sort by height to make sure it is deterministic - sort.Slice(headers, func(i, j int) bool { - return headers[i].Height > headers[j].Height + sort.Slice(btcHeaders, func(i, j int) bool { + return btcHeaders[i].Height <= btcHeaders[j].Height }) - for _, header := range headers { - if err := header.Validate(); err != nil { + headersBytes := make([]bbn.BTCHeaderBytes, len(btcHeaders)) + for i, btcHeader := range btcHeaders { + h := btcHeader + if err := h.Validate(); err != nil { return err } + + headersBytes[i] = *h.Header + } + + if err := k.InsertHeaders(ctx, headersBytes); err != nil { + return err } - k.InsertHeaderInfos(ctx, headers) allBlocks := k.GetMainChainFromWithLimit(ctx, 0, 1) isRetarget := btclighttypes.IsRetargetBlock(allBlocks[0], &chaincfg.SigNetParams) diff --git a/app/upgrades/signetlaunch/upgrades_test.go b/app/upgrades/signetlaunch/upgrades_test.go index d261ac607..b610d3bdd 100644 --- a/app/upgrades/signetlaunch/upgrades_test.go +++ b/app/upgrades/signetlaunch/upgrades_test.go @@ -1,6 +1,7 @@ package signetlaunch_test import ( + "bytes" "fmt" "testing" "time" @@ -11,6 +12,8 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/types" "github.com/babylonlabs-io/babylon/app" v1 "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" + "github.com/babylonlabs-io/babylon/x/btclightclient" + btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" @@ -36,13 +39,31 @@ func (s *UpgradeTestSuite) SetupTest() { s.app = app.Setup(s.T(), false) s.ctx = s.app.BaseApp.NewContextLegacy(false, tmproto.Header{Height: 1, ChainID: "babylon-1", Time: time.Now().UTC()}) s.preModule = upgrade.NewAppModule(s.app.UpgradeKeeper, s.app.AccountKeeper.AddressCodec()) + + var btcHeaderZero btclighttypes.BTCHeaderInfo + // signet btc header 0 + btcHeaderZeroStr := `{ + "header": "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a008f4d5fae77031e8ad22203", + "hash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6", + "work": "77414720" + }` + buff := bytes.NewBufferString(btcHeaderZeroStr) + + err := s.app.EncodingConfig().Codec.UnmarshalJSON(buff.Bytes(), &btcHeaderZero) + s.NoError(err) + + k := s.app.BTCLightClientKeeper + btclightclient.InitGenesis(s.ctx, s.app.BTCLightClientKeeper, btclighttypes.GenesisState{ + Params: k.GetParams(s.ctx), + BtcHeaders: []*btclighttypes.BTCHeaderInfo{&btcHeaderZero}, + }) } func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(UpgradeTestSuite)) } -func (s *UpgradeTestSuite) TestUpgradePayments() { +func (s *UpgradeTestSuite) TestUpgrade() { oldHeadersLen := 0 testCases := []struct { @@ -80,15 +101,18 @@ func (s *UpgradeTestSuite) TestUpgradePayments() { // ensure the btc headers were added allBtcHeaders := s.app.BTCLightClientKeeper.GetMainChainFrom(s.ctx, 0) - btcHeaders, err := v1.LoadBTCHeadersFromData() + btcHeadersInserted, err := v1.LoadBTCHeadersFromData() s.NoError(err) - lenHeadersInserted := len(btcHeaders) + lenHeadersInserted := len(btcHeadersInserted) newHeadersLen := len(allBtcHeaders) s.Equal(newHeadersLen, oldHeadersLen+lenHeadersInserted) - // ensure the headers were inserted at the end - s.Equal(allBtcHeaders[newHeadersLen-lenHeadersInserted:], btcHeaders) + // ensure the headers were inserted as expected + for i, btcHeaderInserted := range btcHeadersInserted { + btcHeaderInState := allBtcHeaders[oldHeadersLen+i] + s.True(btcHeaderInserted.Eq(btcHeaderInState)) + } }, }, } From 4cae2dfa7105c29ba12fb2e30df081748b7db4d3 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 1 Aug 2024 22:13:22 -0300 Subject: [PATCH 22/89] chore: add option to start with specific headers in e2e test init chain genesis --- app/test_helpers.go | 22 +++++++++++++ app/upgrades/signetlaunch/upgrades_test.go | 22 ++++++------- contrib/images/Makefile | 5 ++- test/e2e/configurer/chain/chain.go | 18 +++++++++++ test/e2e/configurer/current.go | 5 ++- test/e2e/configurer/factory.go | 8 +++-- test/e2e/configurer/upgrade.go | 5 ++- test/e2e/containers/containers.go | 10 +++++- test/e2e/initialization/chain/main.go | 24 +++++++++++++- test/e2e/initialization/config.go | 31 +++++++++++++------ test/e2e/initialization/init.go | 11 +++++-- test/e2e/initialization/init_test.go | 4 +-- ...software_upgrade_e2e_signet_launch_test.go | 12 +++++-- test/e2e/software_upgrade_e2e_vanilla_test.go | 2 +- 14 files changed, 143 insertions(+), 36 deletions(-) diff --git a/app/test_helpers.go b/app/test_helpers.go index 08ff94d76..fd3ac6f6d 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -1,6 +1,7 @@ package app import ( + "bytes" "encoding/json" "os" "testing" @@ -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" @@ -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" ) @@ -354,3 +357,22 @@ func initAccountWithCoins(app *BabylonApp, ctx sdk.Context, addr sdk.AccAddress, panic(err) } } + +// SignetBtcHeaderZero returns the BTC Header block zero from signet. +func SignetBtcHeaderZero(cdc codec.Codec) (*btclighttypes.BTCHeaderInfo, error) { + var btcHeaderZero btclighttypes.BTCHeaderInfo + // signet btc header 0 + btcHeaderZeroStr := `{ + "header": "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a008f4d5fae77031e8ad22203", + "hash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6", + "work": "77414720" + }` + buff := bytes.NewBufferString(btcHeaderZeroStr) + + err := cdc.UnmarshalJSON(buff.Bytes(), &btcHeaderZero) + if err != nil { + return nil, err + } + + return &btcHeaderZero, nil +} diff --git a/app/upgrades/signetlaunch/upgrades_test.go b/app/upgrades/signetlaunch/upgrades_test.go index b610d3bdd..98771fe6f 100644 --- a/app/upgrades/signetlaunch/upgrades_test.go +++ b/app/upgrades/signetlaunch/upgrades_test.go @@ -1,7 +1,6 @@ package signetlaunch_test import ( - "bytes" "fmt" "testing" "time" @@ -40,22 +39,13 @@ func (s *UpgradeTestSuite) SetupTest() { s.ctx = s.app.BaseApp.NewContextLegacy(false, tmproto.Header{Height: 1, ChainID: "babylon-1", Time: time.Now().UTC()}) s.preModule = upgrade.NewAppModule(s.app.UpgradeKeeper, s.app.AccountKeeper.AddressCodec()) - var btcHeaderZero btclighttypes.BTCHeaderInfo - // signet btc header 0 - btcHeaderZeroStr := `{ - "header": "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a008f4d5fae77031e8ad22203", - "hash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6", - "work": "77414720" - }` - buff := bytes.NewBufferString(btcHeaderZeroStr) - - err := s.app.EncodingConfig().Codec.UnmarshalJSON(buff.Bytes(), &btcHeaderZero) + btcHeaderZero, err := app.SignetBtcHeaderZero(s.app.EncodingConfig().Codec) s.NoError(err) k := s.app.BTCLightClientKeeper btclightclient.InitGenesis(s.ctx, s.app.BTCLightClientKeeper, btclighttypes.GenesisState{ Params: k.GetParams(s.ctx), - BtcHeaders: []*btclighttypes.BTCHeaderInfo{&btcHeaderZero}, + BtcHeaders: []*btclighttypes.BTCHeaderInfo{btcHeaderZero}, }) } @@ -111,7 +101,13 @@ func (s *UpgradeTestSuite) TestUpgrade() { // ensure the headers were inserted as expected for i, btcHeaderInserted := range btcHeadersInserted { btcHeaderInState := allBtcHeaders[oldHeadersLen+i] - s.True(btcHeaderInserted.Eq(btcHeaderInState)) + + s.EqualValues(btcHeaderInserted.Hash.MarshalHex(), btcHeaderInState.Hash.MarshalHex()) + s.EqualValues(btcHeaderInserted.Header.MarshalHex(), btcHeaderInState.Header.MarshalHex()) + s.EqualValues(btcHeaderInserted.Height, btcHeaderInState.Height) + + // TODO: check why work does not match + // s.EqualValues(btcHeaderInserted.Work.String(), btcHeaderInState.Work.String()) } }, }, diff --git a/contrib/images/Makefile b/contrib/images/Makefile index beef16916..311bb7542 100644 --- a/contrib/images/Makefile +++ b/contrib/images/Makefile @@ -19,10 +19,13 @@ babylond-before-upgrade: babylond-rmi: docker rmi babylonlabs-io/babylond 2>/dev/null; true -e2e-init-chain: +e2e-init-chain: e2e-init-chain-rmi @DOCKER_BUILDKIT=1 docker build -t babylonlabs-io/babylond-e2e-init-chain --build-arg E2E_SCRIPT_NAME=chain --platform=linux/x86_64 \ -f e2e-initialization/init.Dockerfile ${BABYLON_FULL_PATH} +e2e-init-chain-rmi: + docker rmi babylonlabs-io/babylond-e2e-init-chain 2>/dev/null; true + cosmos-relayer: cosmos-relayer-rmi docker build --tag babylonlabs-io/cosmos-relayer:${RELAYER_TAG} -f cosmos-relayer/Dockerfile \ ${BABYLON_FULL_PATH}/contrib/images/cosmos-relayer diff --git a/test/e2e/configurer/chain/chain.go b/test/e2e/configurer/chain/chain.go index c0a5ef195..467206f98 100644 --- a/test/e2e/configurer/chain/chain.go +++ b/test/e2e/configurer/chain/chain.go @@ -1,7 +1,9 @@ package chain import ( + "encoding/hex" "fmt" + "strings" "testing" "time" @@ -15,6 +17,7 @@ import ( "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" "github.com/babylonlabs-io/babylon/test/e2e/containers" "github.com/babylonlabs-io/babylon/test/e2e/initialization" + btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" ) type Config struct { @@ -29,6 +32,7 @@ type Config struct { LatestProposalNumber int LatestLockNumber int NodeConfigs []*NodeConfig + BTCHeaders []*btclighttypes.BTCHeaderInfo IBCConfig *ibctesting.ChannelConfig LatestCodeId int @@ -59,6 +63,7 @@ func New(t *testing.T, containerManager *containers.Manager, id string, initVali ExpeditedVotingPeriod: config.PropDepositBlocks + numVal*config.PropVoteBlocks + config.PropBufferBlocks - 2, t: t, containerManager: containerManager, + BTCHeaders: []*btclighttypes.BTCHeaderInfo{}, } } @@ -182,3 +187,16 @@ func (c *Config) TxGovVoteFromAllNodes(propID int, option govv1.VoteOption, over n.TxGovVote(n.WalletName, propID, option, overallFlags...) } } + +// BTCHeaderBytesHexJoined join all the btc headers as byte string hex +func (c *Config) BTCHeaderBytesHexJoined() string { + strBtcHeaders := make([]string, len(c.BTCHeaders)) + for i, btcHeader := range c.BTCHeaders { + bz, err := btcHeader.Marshal() + if err != nil { + panic(err) + } + strBtcHeaders[i] = hex.EncodeToString(bz) + } + return strings.Join(strBtcHeaders, ",") +} diff --git a/test/e2e/configurer/current.go b/test/e2e/configurer/current.go index ca2c26ae6..8888e78af 100644 --- a/test/e2e/configurer/current.go +++ b/test/e2e/configurer/current.go @@ -51,7 +51,10 @@ func (cb *CurrentBranchConfigurer) ConfigureChain(chainConfig *chain.Config) err tmpDir, chainConfig.ValidatorInitConfigs, time.Duration(chainConfig.VotingPeriod*1000000000), - time.Duration(chainConfig.ExpeditedVotingPeriod*1000000000), 0) + time.Duration(chainConfig.ExpeditedVotingPeriod*1000000000), + 0, + chainConfig.BTCHeaders, + ) if err != nil { return err } diff --git a/test/e2e/configurer/factory.go b/test/e2e/configurer/factory.go index df41dc9a2..cb1507f14 100644 --- a/test/e2e/configurer/factory.go +++ b/test/e2e/configurer/factory.go @@ -6,6 +6,7 @@ import ( "github.com/babylonlabs-io/babylon/test/e2e/configurer/chain" "github.com/babylonlabs-io/babylon/test/e2e/containers" "github.com/babylonlabs-io/babylon/test/e2e/initialization" + btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" zctypes "github.com/babylonlabs-io/babylon/x/zoneconcierge/types" ibctesting "github.com/cosmos/ibc-go/v8/testing" ) @@ -202,17 +203,20 @@ func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, } // NewSoftwareUpgradeConfigurer returns a new Configurer for Software Upgrade testing -func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradePath string) (Configurer, error) { +func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradePath string, btcHeaders []*btclighttypes.BTCHeaderInfo) (Configurer, error) { identifier := t.Name() containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, true) if err != nil { return nil, err } + chainA := chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, nil) + chainA.BTCHeaders = btcHeaders + return NewUpgradeConfigurer(t, []*chain.Config{ // we only need 1 chain for testing upgrade - chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, nil), + chainA, }, withUpgrade(baseSetup), // base set up with upgrade containerManager, diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index 20f5f8bab..b84e7a1f7 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -96,7 +96,10 @@ func (uc *UpgradeConfigurer) ConfigureChain(chainConfig *chain.Config) error { forkHeight = forkHeight - config.ForkHeightPreUpgradeOffset } - chainInitResource, err := uc.containerManager.RunChainInitResource(chainConfig.Id, int(chainConfig.VotingPeriod), int(chainConfig.ExpeditedVotingPeriod), validatorConfigBytes, tmpDir, int(forkHeight)) + chainInitResource, err := uc.containerManager.RunChainInitResource( + chainConfig.Id, int(chainConfig.VotingPeriod), int(chainConfig.ExpeditedVotingPeriod), + validatorConfigBytes, tmpDir, int(forkHeight), chainConfig.BTCHeaderBytesHexJoined(), + ) if err != nil { return err } diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 88f55566d..250025c94 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -353,7 +353,14 @@ func noRestart(config *docker.HostConfig) { // The genesis and configs are to be mounted on the init container as volume on mountDir path. // Returns the container resource and error if any. This method does not Purge the container. The caller // must deal with removing the resource. -func (m *Manager) RunChainInitResource(chainId string, chainVotingPeriod, chainExpeditedVotingPeriod int, validatorConfigBytes []byte, mountDir string, forkHeight int) (*dockertest.Resource, error) { +func (m *Manager) RunChainInitResource( + chainId string, + chainVotingPeriod, chainExpeditedVotingPeriod int, + validatorConfigBytes []byte, + mountDir string, + forkHeight int, + btcHeaders string, +) (*dockertest.Resource, error) { votingPeriodDuration := time.Duration(chainVotingPeriod * 1000000000) expeditedVotingPeriodDuration := time.Duration(chainExpeditedVotingPeriod * 1000000000) @@ -369,6 +376,7 @@ func (m *Manager) RunChainInitResource(chainId string, chainVotingPeriod, chainE fmt.Sprintf("--voting-period=%v", votingPeriodDuration), fmt.Sprintf("--expedited-voting-period=%v", expeditedVotingPeriodDuration), fmt.Sprintf("--fork-height=%v", forkHeight), + fmt.Sprintf("--btc-headers=%s", btcHeaders), }, User: "root:root", Mounts: []string{ diff --git a/test/e2e/initialization/chain/main.go b/test/e2e/initialization/chain/main.go index 6d22e8e78..3f5cb31d4 100644 --- a/test/e2e/initialization/chain/main.go +++ b/test/e2e/initialization/chain/main.go @@ -1,13 +1,16 @@ package main import ( + "encoding/hex" "encoding/json" "flag" "fmt" "os" + "strings" "time" "github.com/babylonlabs-io/babylon/test/e2e/initialization" + btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" ) func main() { @@ -16,6 +19,7 @@ func main() { dataDir string chainId string config string + btcHeadersBytesHexStr string votingPeriod time.Duration expeditedVotingPeriod time.Duration forkHeight int @@ -24,6 +28,7 @@ func main() { flag.StringVar(&dataDir, "data-dir", "", "chain data directory") flag.StringVar(&chainId, "chain-id", "", "chain ID") flag.StringVar(&config, "config", "", "serialized config") + flag.StringVar(&btcHeadersBytesHexStr, "btc-headers", "", "btc header bytes comma separated") flag.DurationVar(&votingPeriod, "voting-period", 30000000000, "voting period") flag.DurationVar(&expeditedVotingPeriod, "expedited-voting-period", 20000000000, "expedited voting period") flag.IntVar(&forkHeight, "fork-height", 0, "fork height") @@ -43,7 +48,24 @@ func main() { panic(err) } - createdChain, err := initialization.InitChain(chainId, dataDir, valConfig, votingPeriod, expeditedVotingPeriod, forkHeight) + btcHeaders := []*btclighttypes.BTCHeaderInfo{} + btcHeadersBytesHex := strings.Split(btcHeadersBytesHexStr, ",") + for _, btcHeaderBytesHex := range btcHeadersBytesHex { + btcHeaderBytes, err := hex.DecodeString(btcHeaderBytesHex) + if err != nil { + panic(err) + } + + btcHeader := &btclighttypes.BTCHeaderInfo{} + err = btcHeader.Unmarshal(btcHeaderBytes) + if err != nil { + panic(err) + } + + btcHeaders = append(btcHeaders, btcHeader) + } + + createdChain, err := initialization.InitChain(chainId, dataDir, valConfig, votingPeriod, expeditedVotingPeriod, forkHeight, btcHeaders) if err != nil { panic(err) } diff --git a/test/e2e/initialization/config.go b/test/e2e/initialization/config.go index 930f9d66a..cb074552d 100644 --- a/test/e2e/initialization/config.go +++ b/test/e2e/initialization/config.go @@ -27,6 +27,7 @@ import ( bbn "github.com/babylonlabs-io/babylon/types" btccheckpointtypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" blctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" + btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" checkpointingtypes "github.com/babylonlabs-io/babylon/x/checkpointing/types" "github.com/babylonlabs-io/babylon/test/e2e/util" @@ -168,7 +169,12 @@ func updateModuleGenesis[V proto.Message](appGenState map[string]json.RawMessage return nil } -func initGenesis(chain *internalChain, votingPeriod, expeditedVotingPeriod time.Duration, forkHeight int) error { +func initGenesis( + chain *internalChain, + votingPeriod, expeditedVotingPeriod time.Duration, + forkHeight int, + btcHeaders []*btclighttypes.BTCHeaderInfo, +) error { // initialize a genesis file configDir := chain.nodes[0].configDir() @@ -248,7 +254,7 @@ func initGenesis(chain *internalChain, votingPeriod, expeditedVotingPeriod time. return err } - err = updateModuleGenesis(appGenState, blctypes.ModuleName, blctypes.DefaultGenesis(), updateBtcLightClientGenesis) + err = updateModuleGenesis(appGenState, blctypes.ModuleName, blctypes.DefaultGenesis(), updateBtcLightClientGenesis(btcHeaders)) if err != nil { return err } @@ -322,14 +328,21 @@ func updateCrisisGenesis(crisisGenState *crisistypes.GenesisState) { crisisGenState.ConstantFee.Denom = BabylonDenom } -func updateBtcLightClientGenesis(blcGenState *blctypes.GenesisState) { - btcSimnetGenesisHex := "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a45068653ffff7f2002000000" - baseBtcHeader, err := bbn.NewBTCHeaderBytesFromHex(btcSimnetGenesisHex) - if err != nil { - panic(err) +func updateBtcLightClientGenesis(btcHeaders []*btclighttypes.BTCHeaderInfo) func(blcGenState *blctypes.GenesisState) { + return func(blcGenState *btclighttypes.GenesisState) { + if len(btcHeaders) > 0 { + blcGenState.BtcHeaders = btcHeaders + return + } + + btcSimnetGenesisHex := "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a45068653ffff7f2002000000" + baseBtcHeader, err := bbn.NewBTCHeaderBytesFromHex(btcSimnetGenesisHex) + if err != nil { + panic(err) + } + work := blctypes.CalcWork(&baseBtcHeader) + blcGenState.BtcHeaders = []*blctypes.BTCHeaderInfo{blctypes.NewBTCHeaderInfo(&baseBtcHeader, baseBtcHeader.Hash(), 0, &work)} } - work := blctypes.CalcWork(&baseBtcHeader) - blcGenState.BtcHeaders = []*blctypes.BTCHeaderInfo{blctypes.NewBTCHeaderInfo(&baseBtcHeader, baseBtcHeader.Hash(), 0, &work)} } func updateBtccheckpointGenesis(btccheckpointGenState *btccheckpointtypes.GenesisState) { diff --git a/test/e2e/initialization/init.go b/test/e2e/initialization/init.go index 94e8ca3e5..af3b9e7bb 100644 --- a/test/e2e/initialization/init.go +++ b/test/e2e/initialization/init.go @@ -8,9 +8,16 @@ import ( appkeepers "github.com/babylonlabs-io/babylon/app/keepers" "github.com/babylonlabs-io/babylon/test/e2e/util" + btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" ) -func InitChain(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod, expeditedVotingPeriod time.Duration, forkHeight int) (*Chain, error) { +func InitChain( + id, dataDir string, + nodeConfigs []*NodeConfig, + votingPeriod, expeditedVotingPeriod time.Duration, + forkHeight int, + btcHeaders []*btclighttypes.BTCHeaderInfo, +) (*Chain, error) { chain, err := new(id, dataDir) if err != nil { return nil, err @@ -24,7 +31,7 @@ func InitChain(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod, expe chain.nodes = append(chain.nodes, newNode) } - if err := initGenesis(chain, votingPeriod, expeditedVotingPeriod, forkHeight); err != nil { + if err := initGenesis(chain, votingPeriod, expeditedVotingPeriod, forkHeight, btcHeaders); err != nil { return nil, err } diff --git a/test/e2e/initialization/init_test.go b/test/e2e/initialization/init_test.go index 8d21b1b4d..a4ba49dab 100644 --- a/test/e2e/initialization/init_test.go +++ b/test/e2e/initialization/init_test.go @@ -51,7 +51,7 @@ func TestChainInit(t *testing.T) { dataDir, err = os.MkdirTemp("", "bbn-e2e-testnet-test") ) - chain, err := initialization.InitChain(id, dataDir, nodeConfigs, time.Second*3, time.Second, forkHeight) + chain, err := initialization.InitChain(id, dataDir, nodeConfigs, time.Second*3, time.Second, forkHeight, nil) require.NoError(t, err) require.Equal(t, chain.ChainMeta.DataDir, dataDir) @@ -109,7 +109,7 @@ func TestSingleNodeInit(t *testing.T) { ) // Setup - existingChain, err := initialization.InitChain(id, dataDir, existingChainNodeConfigs, time.Second*3, time.Second, forkHeight) + existingChain, err := initialization.InitChain(id, dataDir, existingChainNodeConfigs, time.Second*3, time.Second, forkHeight, nil) require.NoError(t, err) actualNode, err := initialization.InitSingleNode(existingChain.ChainMeta.Id, dataDir, filepath.Join(existingChain.Nodes[0].ConfigDir, "config", "genesis.json"), expectedConfig, time.Second*3, 3, "testHash", []string{"some server"}, []string{"some server"}) diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go index 5d2ffd1b5..c6c74f2f1 100644 --- a/test/e2e/software_upgrade_e2e_signet_launch_test.go +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -3,7 +3,10 @@ package e2e import ( "github.com/stretchr/testify/suite" + "github.com/babylonlabs-io/babylon/app" v1 "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" + btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" + "github.com/babylonlabs-io/babylon/test/e2e/configurer" "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" ) @@ -18,7 +21,9 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) SetupSuite() { s.T().Log("setting up e2e integration test suite...") var err error - s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.UpgradeSignetLaunchFilePath) + btcHeaderZero, err := app.SignetBtcHeaderZero(app.NewTmpBabylonApp().AppCodec()) + s.NoError(err) + s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.UpgradeSignetLaunchFilePath, []*btclighttypes.BTCHeaderInfo{btcHeaderZero}) s.NoError(err) err = s.configurer.ConfigureChains() s.NoError(err) @@ -62,6 +67,9 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() { reversedStoredIndex := storedHeadersLen - (oldHeadersStoredLen + i + 1) headerStoredResp := storedBtcHeadersResp[reversedStoredIndex] // reverse reading - s.EqualValues(headerInsertedResp, headerStoredResp) + s.EqualValues(headerInsertedResp.HashHex, headerStoredResp.HashHex) + s.EqualValues(headerInsertedResp.HeaderHex, headerStoredResp.HeaderHex) + s.EqualValues(headerInsertedResp.Height, headerStoredResp.Height) + // s.EqualValues(headerInsertedResp.Work.String(), headerStoredResp.Work.String()) } } diff --git a/test/e2e/software_upgrade_e2e_vanilla_test.go b/test/e2e/software_upgrade_e2e_vanilla_test.go index 9a8570b6d..5988a27f9 100644 --- a/test/e2e/software_upgrade_e2e_vanilla_test.go +++ b/test/e2e/software_upgrade_e2e_vanilla_test.go @@ -18,7 +18,7 @@ func (s *SoftwareUpgradeVanillaTestSuite) SetupSuite() { s.T().Log("setting up e2e integration test suite...") var err error - s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.UpgradeVanillaFilePath) + s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.UpgradeVanillaFilePath, nil) s.NoError(err) err = s.configurer.ConfigureChains() s.NoError(err) From e10c0324cae4bd87f0c6ec80fe044c39f5a89e5f Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 2 Aug 2024 09:04:22 -0300 Subject: [PATCH 23/89] chore: update to use only btc header bytes to upgrade --- app/upgrades/signetlaunch/data_btc_headers.go | 75 ++++--------------- app/upgrades/signetlaunch/upgrades.go | 10 --- app/upgrades/signetlaunch/upgrades_test.go | 5 -- ...software_upgrade_e2e_signet_launch_test.go | 7 +- 4 files changed, 17 insertions(+), 80 deletions(-) diff --git a/app/upgrades/signetlaunch/data_btc_headers.go b/app/upgrades/signetlaunch/data_btc_headers.go index 2c5479fb9..408de35f3 100644 --- a/app/upgrades/signetlaunch/data_btc_headers.go +++ b/app/upgrades/signetlaunch/data_btc_headers.go @@ -3,94 +3,49 @@ package signetlaunch const NewBtcHeadersStr = `{ "btc_headers": [ { - "header": "00000020f61eee3b63a380a477a063af32b2bbc97c9ff9f01f2c4225e973988108000000f575c83235984e7dc4afc1f30944c170462e84437ab6f2d52e16878a79e4678bd1914d5fae77031eccf40700", - "hash": "00000086d6b2636cb2a392d45edc4ec544a10024d30141c9adf4bfd9de533b53", - "height": 1, - "work": "77414720" + "header": "00000020f61eee3b63a380a477a063af32b2bbc97c9ff9f01f2c4225e973988108000000f575c83235984e7dc4afc1f30944c170462e84437ab6f2d52e16878a79e4678bd1914d5fae77031eccf40700" }, { - "header": "00000020533b53ded9bff4adc94101d32400a144c54edc5ed492a3b26c63b2d686000000b38fef50592017cfafbcab88eb3d9cf50b2c801711cad8299495d26df5e54812e7914d5fae77031ecfdd0b00", - "hash": "00000032bb881de703dcc968e8258080c7ed4a2933e3a35888fa0b2f75f36029", - "height": 2, - "work": "77414720" + "header": "00000020533b53ded9bff4adc94101d32400a144c54edc5ed492a3b26c63b2d686000000b38fef50592017cfafbcab88eb3d9cf50b2c801711cad8299495d26df5e54812e7914d5fae77031ecfdd0b00" }, { - "header": "000000202960f3752f0bfa8858a3e333294aedc7808025e868c9dc03e71d88bb320000007765fcd3d5b4966beb338bba2675dc2cf2ad28d4ad1d83bdb6f286e7e27ac1f807924d5fae77031e81d60b00", - "hash": "000000e8daac2a2e973ecaab46dc948181c638adecf5ae0fd5d3e13aa14364b0", - "height": 3, - "work": "77414720" + "header": "000000202960f3752f0bfa8858a3e333294aedc7808025e868c9dc03e71d88bb320000007765fcd3d5b4966beb338bba2675dc2cf2ad28d4ad1d83bdb6f286e7e27ac1f807924d5fae77031e81d60b00" }, { - "header": "00000020b06443a13ae1d3d50faef5ecad38c6818194dc46abca3e972e2aacdae800000069a5829097e80fee00ac49a56ea9f82d741a6af84d32b3bc455cf31871e2a8ac27924d5fae77031e9c910500", - "hash": "00000194763f1233e40afd5f6eb2e64abd2e5e158a4139198a224f8a7503d47e", - "height": 4, - "work": "77414720" + "header": "00000020b06443a13ae1d3d50faef5ecad38c6818194dc46abca3e972e2aacdae800000069a5829097e80fee00ac49a56ea9f82d741a6af84d32b3bc455cf31871e2a8ac27924d5fae77031e9c910500" }, { - "header": "000000207ed403758a4f228a1939418a155e2ebd4ae6b26e5ffd0ae433123f7694010000542e80b609c5bc58af5bdf492e26d4f60cd43a3966c2e063c50444c29b3757a636924d5fae77031ee8601d00", - "hash": "000003776c984edd753b876f0e70d08450f92dd76a768df03d2c42d1880aea5b", - "height": 5, - "work": "77414720" + "header": "000000207ed403758a4f228a1939418a155e2ebd4ae6b26e5ffd0ae433123f7694010000542e80b609c5bc58af5bdf492e26d4f60cd43a3966c2e063c50444c29b3757a636924d5fae77031ee8601d00" }, { - "header": "000000205bea0a88d1422c3df08d766ad72df95084d0700e6f873b75dd4e986c7703000002b57516d33ed60c2bdd9f93d6d5614083324c837e68e5ba6e04287a7285633585924d5fae77031ed1719600", - "hash": "000001b62ff822d0b1c68e231670eba2cf8d494075f9616447194b370db6f3da", - "height": 6, - "work": "77414720" + "header": "000000205bea0a88d1422c3df08d766ad72df95084d0700e6f873b75dd4e986c7703000002b57516d33ed60c2bdd9f93d6d5614083324c837e68e5ba6e04287a7285633585924d5fae77031ed1719600" }, { - "header": "00000020daf3b60d374b19476461f97540498dcfa2eb7016238ec6b1d022f82fb60100007a7ae65b53cb988c2ec92d2384996713821d5645ffe61c9acea60da75cd5edfa1a944d5fae77031e9dbb0500", - "hash": "000000b6f018c5b53240616c7868eab7e1338de4200ec25b65a5e1c2f3c57c45", - "height": 7, - "work": "77414720" + "header": "00000020daf3b60d374b19476461f97540498dcfa2eb7016238ec6b1d022f82fb60100007a7ae65b53cb988c2ec92d2384996713821d5645ffe61c9acea60da75cd5edfa1a944d5fae77031e9dbb0500" }, { - "header": "00000020457cc5f3c2e1a5655bc20e20e48d33e1b7ea68786c614032b5c518f0b6000000541f36942d82c6e7248275ff15c8933487fbe1819c67a9ecc0f4b70bb7e6cf672a944d5fae77031e8f398600", - "hash": "000002213230ed813e42076f753f666244db421b3e36a3a3ba31384feb61eba2", - "height": 8, - "work": "77414720" + "header": "00000020457cc5f3c2e1a5655bc20e20e48d33e1b7ea68786c614032b5c518f0b6000000541f36942d82c6e7248275ff15c8933487fbe1819c67a9ecc0f4b70bb7e6cf672a944d5fae77031e8f398600" }, { - "header": "00000020a2eb61eb4f3831baa3a3363e1b42db4462663f756f07423e81ed30322102000077224de7dea0f8d0ec22b1d2e2e255f0a987b96fe7200e1a2e6373f48a2f5b7894954d5fae77031e36867e00", - "hash": "000001e163d0a8e294c3406a713ba4363f422f1322a1d6ab6de4e54b51e868a8", - "height": 9, - "work": "77414720" + "header": "00000020a2eb61eb4f3831baa3a3363e1b42db4462663f756f07423e81ed30322102000077224de7dea0f8d0ec22b1d2e2e255f0a987b96fe7200e1a2e6373f48a2f5b7894954d5fae77031e36867e00" }, { - "header": "00000020a868e8514be5e46dabd6a122132f423f36a43b716a40c394e2a8d063e1010000f4c6c717e99d800c699c25a2006a75a0c5c09f432a936f385e6fce139cdbd1a5e9964d5fae77031e7d026e00", - "hash": "000001418e9af8310ef3644093dbc4a8ad9edb0c9ac80397f3479ad1729d965b", - "height": 10, - "work": "77414720" + "header": "00000020a868e8514be5e46dabd6a122132f423f36a43b716a40c394e2a8d063e1010000f4c6c717e99d800c699c25a2006a75a0c5c09f432a936f385e6fce139cdbd1a5e9964d5fae77031e7d026e00" }, { - "header": "000000205b969d72d19a47f39703c89a0cdb9eada8c4db934064f30e31f89a8e41010000949eef89068ffc76bf4dca6762e26581d410d0df40edf147d4ffdc6dea404a1512984d5fae77031ee67c1200", - "hash": "0000034cdfe52a76f70f137be5b44dd2d10b305d03a42229767ec5b524d81094", - "height": 11, - "work": "77414720" + "header": "000000205b969d72d19a47f39703c89a0cdb9eada8c4db934064f30e31f89a8e41010000949eef89068ffc76bf4dca6762e26581d410d0df40edf147d4ffdc6dea404a1512984d5fae77031ee67c1200" }, { - "header": "000000209410d824b5c57e762922a4035d300bd1d24db4e57b130ff7762ae5df4c030000532299955b2dc6bd7c13c267d3c0990fefdf7aec3bcbab5b2c85d0d36316f93644984d5fae77031ecdea1600", - "hash": "000000375d267acf5e788946bd885735d215a98e13eb1b1dcb79403a4549f609", - "height": 12, - "work": "77414720" + "header": "000000209410d824b5c57e762922a4035d300bd1d24db4e57b130ff7762ae5df4c030000532299955b2dc6bd7c13c267d3c0990fefdf7aec3bcbab5b2c85d0d36316f93644984d5fae77031ecdea1600" }, { - "header": "0000002009f649453a4079cb1d1beb138ea915d2355788bd4689785ecf7a265d3700000010bd26b43a88350e614736674431e62cc7c77dc577d07edd80620a02339d5fab82984d5fae77031efe682400", - "hash": "000000aa98270ecd860f5b0f34eed287b66a24b80738eeb9b5e7a65791ffb935", - "height": 13, - "work": "77414720" + "header": "0000002009f649453a4079cb1d1beb138ea915d2355788bd4689785ecf7a265d3700000010bd26b43a88350e614736674431e62cc7c77dc577d07edd80620a02339d5fab82984d5fae77031efe682400" }, { - "header": "0000002035b9ff9157a6e7b5b9ee3807b8246ab687d2ee340f5b0f86cd0e2798aa00000028ef48260b3c0d45bbe5321335b05dde8fcb130e063202457884585298b8a5dde4984d5fae77031ec0a08600", - "hash": "00000150de45736bb5158f63a94b9570540d68871eaa8fa03141d16ffb2f1086", - "height": 14, - "work": "77414720" + "header": "0000002035b9ff9157a6e7b5b9ee3807b8246ab687d2ee340f5b0f86cd0e2798aa00000028ef48260b3c0d45bbe5321335b05dde8fcb130e063202457884585298b8a5dde4984d5fae77031ec0a08600" }, { - "header": "0000002086102ffb6fd14131a08faa1e87680d5470954ba9638f15b56b7345de500100009f423c63aa6d39330082b58808013a85af5a7f338a7a3587f0a85b587665e6174e9a4d5fae77031e79353a00", - "hash": "0000013aadf507653857ebf15a210e31aa7be6d02d1608602a1d4906a08cf528", - "height": 15, - "work": "77414720" + "header": "0000002086102ffb6fd14131a08faa1e87680d5470954ba9638f15b56b7345de500100009f423c63aa6d39330082b58808013a85af5a7f338a7a3587f0a85b587665e6174e9a4d5fae77031e79353a00" } ] }` diff --git a/app/upgrades/signetlaunch/upgrades.go b/app/upgrades/signetlaunch/upgrades.go index 8d6565c41..7460a7f2d 100644 --- a/app/upgrades/signetlaunch/upgrades.go +++ b/app/upgrades/signetlaunch/upgrades.go @@ -8,7 +8,6 @@ import ( "context" "errors" "fmt" - "sort" store "cosmossdk.io/store/types" upgradetypes "cosmossdk.io/x/upgrade/types" @@ -89,18 +88,9 @@ func insertBtcHeaders( return errors.New("no headers to insert") } - // sort by height to make sure it is deterministic - sort.Slice(btcHeaders, func(i, j int) bool { - return btcHeaders[i].Height <= btcHeaders[j].Height - }) - headersBytes := make([]bbn.BTCHeaderBytes, len(btcHeaders)) for i, btcHeader := range btcHeaders { h := btcHeader - if err := h.Validate(); err != nil { - return err - } - headersBytes[i] = *h.Header } diff --git a/app/upgrades/signetlaunch/upgrades_test.go b/app/upgrades/signetlaunch/upgrades_test.go index 98771fe6f..dca7bf44b 100644 --- a/app/upgrades/signetlaunch/upgrades_test.go +++ b/app/upgrades/signetlaunch/upgrades_test.go @@ -102,12 +102,7 @@ func (s *UpgradeTestSuite) TestUpgrade() { for i, btcHeaderInserted := range btcHeadersInserted { btcHeaderInState := allBtcHeaders[oldHeadersLen+i] - s.EqualValues(btcHeaderInserted.Hash.MarshalHex(), btcHeaderInState.Hash.MarshalHex()) s.EqualValues(btcHeaderInserted.Header.MarshalHex(), btcHeaderInState.Header.MarshalHex()) - s.EqualValues(btcHeaderInserted.Height, btcHeaderInState.Height) - - // TODO: check why work does not match - // s.EqualValues(btcHeaderInserted.Work.String(), btcHeaderInState.Work.String()) } }, }, diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go index c6c74f2f1..846f4ca6f 100644 --- a/test/e2e/software_upgrade_e2e_signet_launch_test.go +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -63,13 +63,10 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() { // ensure the headers were inserted at the end for i := 0; i < lenHeadersInserted; i++ { - headerInsertedResp := btcHeadersInserted[i].ToResponse() + headerInserted := btcHeadersInserted[i] reversedStoredIndex := storedHeadersLen - (oldHeadersStoredLen + i + 1) headerStoredResp := storedBtcHeadersResp[reversedStoredIndex] // reverse reading - s.EqualValues(headerInsertedResp.HashHex, headerStoredResp.HashHex) - s.EqualValues(headerInsertedResp.HeaderHex, headerStoredResp.HeaderHex) - s.EqualValues(headerInsertedResp.Height, headerStoredResp.Height) - // s.EqualValues(headerInsertedResp.Work.String(), headerStoredResp.Work.String()) + s.EqualValues(headerInserted.Header.MarshalHex(), headerStoredResp.HeaderHex) } } From 8dd3deb2896a7ef055d7cee7f38b92b1ba6eda6e Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 2 Aug 2024 10:05:46 -0300 Subject: [PATCH 24/89] chore: increase timeout of e2e test to 30m --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 058d5fc9c..275bdbc5b 100644 --- a/Makefile +++ b/Makefile @@ -255,7 +255,7 @@ endif .PHONY: run-tests test test-all $(TEST_TARGETS) test-e2e: build-docker-e2e - go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -count=1 --tags=e2e + go test -mod=readonly -timeout=30m -v $(PACKAGES_E2E) -count=1 --tags=e2e test-sim-nondeterminism: @echo "Running non-determinism test..." From 199d0dc1436cafc2c8683a5a88881beddb8e3034 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 2 Aug 2024 10:47:18 -0300 Subject: [PATCH 25/89] chore: add check for cases where btc headers are not needed to specify --- test/e2e/configurer/chain/chain.go | 4 ++++ test/e2e/configurer/factory.go | 4 +++- test/e2e/initialization/chain/main.go | 30 +++++++++++++++++---------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/test/e2e/configurer/chain/chain.go b/test/e2e/configurer/chain/chain.go index 467206f98..137d002e0 100644 --- a/test/e2e/configurer/chain/chain.go +++ b/test/e2e/configurer/chain/chain.go @@ -190,6 +190,10 @@ func (c *Config) TxGovVoteFromAllNodes(propID int, option govv1.VoteOption, over // BTCHeaderBytesHexJoined join all the btc headers as byte string hex func (c *Config) BTCHeaderBytesHexJoined() string { + if c.BTCHeaders == nil || len(c.BTCHeaders) == 0 { + return "" + } + strBtcHeaders := make([]string, len(c.BTCHeaders)) for i, btcHeader := range c.BTCHeaders { bz, err := btcHeader.Marshal() diff --git a/test/e2e/configurer/factory.go b/test/e2e/configurer/factory.go index cb1507f14..c2ade1e98 100644 --- a/test/e2e/configurer/factory.go +++ b/test/e2e/configurer/factory.go @@ -211,7 +211,9 @@ func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradeP } chainA := chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, nil) - chainA.BTCHeaders = btcHeaders + if btcHeaders != nil { + chainA.BTCHeaders = btcHeaders + } return NewUpgradeConfigurer(t, []*chain.Config{ diff --git a/test/e2e/initialization/chain/main.go b/test/e2e/initialization/chain/main.go index 3f5cb31d4..9f251c9f9 100644 --- a/test/e2e/initialization/chain/main.go +++ b/test/e2e/initialization/chain/main.go @@ -48,7 +48,25 @@ func main() { panic(err) } + btcHeaders := btcHeaderFromFlag(btcHeadersBytesHexStr) + createdChain, err := initialization.InitChain(chainId, dataDir, valConfig, votingPeriod, expeditedVotingPeriod, forkHeight, btcHeaders) + if err != nil { + panic(err) + } + + b, _ := json.Marshal(createdChain) + fileName := fmt.Sprintf("%v/%v-encode", dataDir, chainId) + if err = os.WriteFile(fileName, b, 0o777); err != nil { + panic(err) + } +} + +func btcHeaderFromFlag(btcHeadersBytesHexStr string) []*btclighttypes.BTCHeaderInfo { btcHeaders := []*btclighttypes.BTCHeaderInfo{} + if len(btcHeadersBytesHexStr) == 0 { + return btcHeaders + } + btcHeadersBytesHex := strings.Split(btcHeadersBytesHexStr, ",") for _, btcHeaderBytesHex := range btcHeadersBytesHex { btcHeaderBytes, err := hex.DecodeString(btcHeaderBytesHex) @@ -64,15 +82,5 @@ func main() { btcHeaders = append(btcHeaders, btcHeader) } - - createdChain, err := initialization.InitChain(chainId, dataDir, valConfig, votingPeriod, expeditedVotingPeriod, forkHeight, btcHeaders) - if err != nil { - panic(err) - } - - b, _ := json.Marshal(createdChain) - fileName := fmt.Sprintf("%v/%v-encode", dataDir, chainId) - if err = os.WriteFile(fileName, b, 0o777); err != nil { - panic(err) - } + return btcHeaders } From 0b50fe6f8abacbbdb265ffc152487cbdff7cbe6a Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 2 Aug 2024 10:47:31 -0300 Subject: [PATCH 26/89] fix: use identifier for networks --- test/e2e/containers/containers.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 250025c94..da91e4067 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -41,22 +41,22 @@ type Manager struct { // NewManager creates a new Manager instance and initializes // all Docker specific utilities. Returns an error if initialization fails. -func NewManager(identifier string, isDebugLogEnabled bool, isCosmosRelayer, isUpgrade bool) (docker *Manager, err error) { - docker = &Manager{ +func NewManager(identifier string, isDebugLogEnabled bool, isCosmosRelayer, isUpgrade bool) (m *Manager, err error) { + m = &Manager{ ImageConfig: NewImageConfig(isCosmosRelayer, isUpgrade), resources: make(map[string]*dockertest.Resource), isDebugLogEnabled: isDebugLogEnabled, identifier: identifier, } - docker.pool, err = dockertest.NewPool("") + m.pool, err = dockertest.NewPool("") if err != nil { return nil, err } - docker.network, err = docker.pool.CreateNetwork("bbn-testnet") + m.network, err = m.pool.CreateNetwork(m.NetworkName()) if err != nil { return nil, err } - return docker, nil + return m, nil } // ExecTxCmd Runs ExecTxCmdWithSuccessString searching for `code: 0` From 2500087c63e0c15e439c9b5c7d9fc28129122d7a Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 2 Aug 2024 13:26:48 -0300 Subject: [PATCH 27/89] chore: free disk space --- .github/workflows/ci.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 859d3b1cf..40005d2a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,14 +7,17 @@ on: jobs: lint_test: - uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 - with: - run-unit-tests: true - run-integration-tests: true - run-lint: true - integration-tests-command: | - sudo make test-e2e - + runs-on: ubuntu-latest + steps: + - uses: jlumbroso/free-disk-space@main + # - uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 + # with: + # run-unit-tests: true + # run-integration-tests: true + # run-lint: true + # integration-tests-command: | + # sudo make test-e2e + docker_pipeline: uses: babylonchain/.github/.github/workflows/reusable_docker_pipeline.yml@v0.1.0 secrets: inherit From d1ef810b381655e6b6ee8c77747372e03f1bec08 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 2 Aug 2024 13:27:23 -0300 Subject: [PATCH 28/89] chore: turn back to e2e testing --- .github/workflows/ci.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40005d2a9..eb29e8aa1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,16 +7,13 @@ on: jobs: lint_test: - runs-on: ubuntu-latest - steps: - - uses: jlumbroso/free-disk-space@main - # - uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 - # with: - # run-unit-tests: true - # run-integration-tests: true - # run-lint: true - # integration-tests-command: | - # sudo make test-e2e + uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 + with: + run-unit-tests: true + run-integration-tests: true + run-lint: true + integration-tests-command: | + sudo make test-e2e docker_pipeline: uses: babylonchain/.github/.github/workflows/reusable_docker_pipeline.yml@v0.1.0 From 73c75851122fa3037e7040689b67ee6c672cf887 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 2 Aug 2024 13:44:04 -0300 Subject: [PATCH 29/89] chore: add free disk space as need --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb29e8aa1..79b185fa4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,15 @@ on: - '**' jobs: + free-disk-space: + runs-on: ubuntu-latest + steps: + + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + lint_test: + needs: free-disk-space uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 with: run-unit-tests: true From 6083067db993e008a55e462358202561bef86506 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 2 Aug 2024 14:20:14 -0300 Subject: [PATCH 30/89] chore: remove free disk space --- .github/workflows/ci.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79b185fa4..eb29e8aa1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,15 +6,7 @@ on: - '**' jobs: - free-disk-space: - runs-on: ubuntu-latest - steps: - - - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@main - lint_test: - needs: free-disk-space uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 with: run-unit-tests: true From 6c3a8980de0b75301af608dd419208254e6f2aef Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 5 Aug 2024 11:00:27 -0300 Subject: [PATCH 31/89] chore: insert headers without trigger hook and events --- app/upgrades/signetlaunch/upgrades.go | 2 +- x/btclightclient/keeper/keeper.go | 54 ++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/app/upgrades/signetlaunch/upgrades.go b/app/upgrades/signetlaunch/upgrades.go index 7460a7f2d..de81f5f87 100644 --- a/app/upgrades/signetlaunch/upgrades.go +++ b/app/upgrades/signetlaunch/upgrades.go @@ -94,7 +94,7 @@ func insertBtcHeaders( headersBytes[i] = *h.Header } - if err := k.InsertHeaders(ctx, headersBytes); err != nil { + if err := k.InsertHeadersNoEventsAndRollback(ctx, headersBytes); err != nil { return err } diff --git a/x/btclightclient/keeper/keeper.go b/x/btclightclient/keeper/keeper.go index 74b36409e..00dec87ef 100644 --- a/x/btclightclient/keeper/keeper.go +++ b/x/btclightclient/keeper/keeper.go @@ -99,13 +99,49 @@ func (k Keeper) insertHeaders( k.triggerRollBack(ctx, result.RollbackInfo.HeaderToRollbackTo) } + k.insertHeadersFromInsertResult(ctx, result, true) + return nil +} + +func (k Keeper) insertHeadersNoEventsAndRollback( + ctx context.Context, + headers []*wire.BlockHeader, +) error { + headerState := k.headersState(ctx) + + result, err := k.bl.InsertHeaders( + headerState, + headers, + ) + if err != nil { + return err + } + + // if we receive rollback, should return error + if result.RollbackInfo != nil { + return fmt.Errorf("rollback should not happend %+v", result.RollbackInfo) + } + + k.insertHeadersFromInsertResult(ctx, result, false) + return nil +} + +func (k Keeper) insertHeadersFromInsertResult( + ctx context.Context, + result *types.InsertResult, + triggerEventsAndHooks bool, +) { + headerState := k.headersState(ctx) + for _, header := range result.HeadersToInsert { h := header headerState.insertHeader(h) + if !triggerEventsAndHooks { + continue + } k.triggerHeaderInserted(ctx, h) k.triggerRollForward(ctx, h) } - return nil } // InsertHeaderInfos inserts multiple headers info at the store. @@ -121,12 +157,26 @@ func (k Keeper) InsertHeaders(ctx context.Context, headers []bbn.BTCHeaderBytes) return types.ErrEmptyMessage } + blockHeaders := btcHeadersBytesToBlockHeader(headers) + return k.insertHeaders(ctx, blockHeaders) +} + +func (k Keeper) InsertHeadersNoEventsAndRollback(ctx context.Context, headers []bbn.BTCHeaderBytes) error { + if len(headers) == 0 { + return types.ErrEmptyMessage + } + + blockHeaders := btcHeadersBytesToBlockHeader(headers) + return k.insertHeadersNoEventsAndRollback(ctx, blockHeaders) +} + +func btcHeadersBytesToBlockHeader(headers []bbn.BTCHeaderBytes) []*wire.BlockHeader { blockHeaders := make([]*wire.BlockHeader, len(headers)) for i, header := range headers { blockHeaders[i] = header.ToBlockHeader() } - return k.insertHeaders(ctx, blockHeaders) + return blockHeaders } // BlockHeight returns the height of the provided header From b8a4ea5fb87e4ee500978173b60850a89c16e7fb Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 5 Aug 2024 11:35:57 -0300 Subject: [PATCH 32/89] chore: remove command that was removing docker images before build --- contrib/images/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contrib/images/Makefile b/contrib/images/Makefile index 311bb7542..1c9b7e82c 100644 --- a/contrib/images/Makefile +++ b/contrib/images/Makefile @@ -12,14 +12,13 @@ babylond-e2e: babylond-rmi --build-arg BUILD_TAGS="e2e" babylond-before-upgrade: - docker rmi babylonlabs-io/babylond-before-upgrade 2>/dev/null; true && \ docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile \ --build-arg VERSION="${BABYLON_VERSION_BEFORE_UPGRADE}" ${BABYLON_FULL_PATH} babylond-rmi: docker rmi babylonlabs-io/babylond 2>/dev/null; true -e2e-init-chain: e2e-init-chain-rmi +e2e-init-chain: @DOCKER_BUILDKIT=1 docker build -t babylonlabs-io/babylond-e2e-init-chain --build-arg E2E_SCRIPT_NAME=chain --platform=linux/x86_64 \ -f e2e-initialization/init.Dockerfile ${BABYLON_FULL_PATH} From 853952ad3146fe1b73ead0dc37666b7af502d622 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 5 Aug 2024 11:36:24 -0300 Subject: [PATCH 33/89] chore: free disk sapce before run --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb29e8aa1..c83133955 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,16 @@ on: - '**' jobs: + free-disk-space: + runs-on: ubuntu-latest + steps: + + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + + lint_test: + needs: free-disk-space uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 with: run-unit-tests: true From 7b5908f4eef3c490584a8cbb3b738292184797a1 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 5 Aug 2024 12:36:00 -0300 Subject: [PATCH 34/89] chore: remove free disk space --- .github/workflows/ci.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c83133955..eb29e8aa1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,16 +6,7 @@ on: - '**' jobs: - free-disk-space: - runs-on: ubuntu-latest - steps: - - - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@main - - lint_test: - needs: free-disk-space uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 with: run-unit-tests: true From bd9263d61616c8f83b032e713e4d8dceea3148a5 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 5 Aug 2024 13:31:20 -0300 Subject: [PATCH 35/89] chore: wait for clear resources before remove all the directories --- test/e2e/configurer/base.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/configurer/base.go b/test/e2e/configurer/base.go index de34baa2e..38ae526db 100644 --- a/test/e2e/configurer/base.go +++ b/test/e2e/configurer/base.go @@ -40,11 +40,11 @@ const defaultSyncUntilHeight = 3 func (bc *baseConfigurer) ClearResources() error { bc.t.Log("tearing down e2e integration test suite...") - g := new(errgroup.Group) - g.Go(func() error { - return bc.containerManager.ClearResources() - }) + if err := bc.containerManager.ClearResources(); err != nil { + return err + } + g := new(errgroup.Group) for _, chainConfig := range bc.chainConfigs { chainConfig := chainConfig g.Go(func() error { From c3de831e686256b621ad004f8f348c8b95c8b647 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 5 Aug 2024 13:59:26 -0300 Subject: [PATCH 36/89] chore: refactory insert of headers to avoid bool parameter --- app/upgrades/signetlaunch/upgrades.go | 2 +- testutil/datagen/btc_header_info.go | 2 +- x/btclightclient/keeper/keeper.go | 105 +++++++++--------- x/btclightclient/keeper/keeper_test.go | 22 ++-- x/btclightclient/keeper/msg_server.go | 2 +- x/monitor/keeper/grpc_query_test.go | 4 +- .../keeper/ibc_packet_btc_timestamp_test.go | 2 +- x/zoneconcierge/types/btc_timestamp.go | 2 +- 8 files changed, 73 insertions(+), 68 deletions(-) diff --git a/app/upgrades/signetlaunch/upgrades.go b/app/upgrades/signetlaunch/upgrades.go index de81f5f87..7460a7f2d 100644 --- a/app/upgrades/signetlaunch/upgrades.go +++ b/app/upgrades/signetlaunch/upgrades.go @@ -94,7 +94,7 @@ func insertBtcHeaders( headersBytes[i] = *h.Header } - if err := k.InsertHeadersNoEventsAndRollback(ctx, headersBytes); err != nil { + if err := k.InsertHeaders(ctx, headersBytes); err != nil { return err } diff --git a/testutil/datagen/btc_header_info.go b/testutil/datagen/btc_header_info.go index 91230a1dd..c680acdef 100644 --- a/testutil/datagen/btc_header_info.go +++ b/testutil/datagen/btc_header_info.go @@ -294,7 +294,7 @@ func GenRandBtcChainInsertingInKeeper( genesisHeaderInfo, uint32(chainLength), ) - err := k.InsertHeaders(ctx, randomChain.ChainToBytes()) + err := k.InsertHeadersWithHookAndEvents(ctx, randomChain.ChainToBytes()) require.NoError(t, err) tip := k.GetTipInfo(ctx) randomChainTipInfo := randomChain.GetTipInfo() diff --git a/x/btclightclient/keeper/keeper.go b/x/btclightclient/keeper/keeper.go index 00dec87ef..f3df98e84 100644 --- a/x/btclightclient/keeper/keeper.go +++ b/x/btclightclient/keeper/keeper.go @@ -75,37 +75,65 @@ func (k *Keeper) SetHooks(bh types.BTCLightClientHooks) *Keeper { return k } -func (k Keeper) insertHeaders( - ctx context.Context, - headers []*wire.BlockHeader, -) error { +func (k Keeper) insertHandler() func(ctx context.Context, s headersState, result *types.InsertResult) error { + return func(ctx context.Context, s headersState, result *types.InsertResult) error { + // if we receive rollback, should return error + if result.RollbackInfo != nil { + return fmt.Errorf("rollback should not happend %+v", result.RollbackInfo) + } - headerState := k.headersState(ctx) + for _, header := range result.HeadersToInsert { + h := header + s.insertHeader(h) + } + return nil + } +} - result, err := k.bl.InsertHeaders( - headerState, - headers, - ) +func (k Keeper) triggerEventAndHandleHooksHandler() func(ctx context.Context, s headersState, result *types.InsertResult) error { + return func(ctx context.Context, s headersState, result *types.InsertResult) error { + // if we have rollback, first delete all headers up to the rollback point + if result.RollbackInfo != nil { + // roll back to the height + s.rollBackHeadersUpTo(result.RollbackInfo.HeaderToRollbackTo.Height) + // trigger rollback event + k.triggerRollBack(ctx, result.RollbackInfo.HeaderToRollbackTo) + } - if err != nil { - return err + for _, header := range result.HeadersToInsert { + h := header + s.insertHeader(h) + k.triggerHeaderInserted(ctx, h) + k.triggerRollForward(ctx, h) + } + return nil } +} - // if we have rollback, first delete all headers up to the rollback point - if result.RollbackInfo != nil { - // roll back to the height - headerState.rollBackHeadersUpTo(result.RollbackInfo.HeaderToRollbackTo.Height) - // trigger rollback event - k.triggerRollBack(ctx, result.RollbackInfo.HeaderToRollbackTo) - } +func (k Keeper) insertHeadersWithHookAndEvents( + ctx context.Context, + headers []*wire.BlockHeader) error { + return k.insertHeadersInternal( + ctx, + headers, + k.triggerEventAndHandleHooksHandler(), + ) +} - k.insertHeadersFromInsertResult(ctx, result, true) - return nil +func (k Keeper) insertHeaders( + ctx context.Context, + headers []*wire.BlockHeader) error { + return k.insertHeadersInternal( + ctx, + headers, + k.insertHandler(), + ) } -func (k Keeper) insertHeadersNoEventsAndRollback( +func (k Keeper) insertHeadersInternal( ctx context.Context, headers []*wire.BlockHeader, + handleInsertResult func(ctx context.Context, s headersState, result *types.InsertResult) error, ) error { headerState := k.headersState(ctx) @@ -113,35 +141,12 @@ func (k Keeper) insertHeadersNoEventsAndRollback( headerState, headers, ) + if err != nil { return err } - // if we receive rollback, should return error - if result.RollbackInfo != nil { - return fmt.Errorf("rollback should not happend %+v", result.RollbackInfo) - } - - k.insertHeadersFromInsertResult(ctx, result, false) - return nil -} - -func (k Keeper) insertHeadersFromInsertResult( - ctx context.Context, - result *types.InsertResult, - triggerEventsAndHooks bool, -) { - headerState := k.headersState(ctx) - - for _, header := range result.HeadersToInsert { - h := header - headerState.insertHeader(h) - if !triggerEventsAndHooks { - continue - } - k.triggerHeaderInserted(ctx, h) - k.triggerRollForward(ctx, h) - } + return handleInsertResult(ctx, headerState, result) } // InsertHeaderInfos inserts multiple headers info at the store. @@ -152,22 +157,22 @@ func (k Keeper) InsertHeaderInfos(ctx context.Context, infos []*types.BTCHeaderI } } -func (k Keeper) InsertHeaders(ctx context.Context, headers []bbn.BTCHeaderBytes) error { +func (k Keeper) InsertHeadersWithHookAndEvents(ctx context.Context, headers []bbn.BTCHeaderBytes) error { if len(headers) == 0 { return types.ErrEmptyMessage } blockHeaders := btcHeadersBytesToBlockHeader(headers) - return k.insertHeaders(ctx, blockHeaders) + return k.insertHeadersWithHookAndEvents(ctx, blockHeaders) } -func (k Keeper) InsertHeadersNoEventsAndRollback(ctx context.Context, headers []bbn.BTCHeaderBytes) error { +func (k Keeper) InsertHeaders(ctx context.Context, headers []bbn.BTCHeaderBytes) error { if len(headers) == 0 { return types.ErrEmptyMessage } blockHeaders := btcHeadersBytesToBlockHeader(headers) - return k.insertHeadersNoEventsAndRollback(ctx, blockHeaders) + return k.insertHeaders(ctx, blockHeaders) } func btcHeadersBytesToBlockHeader(headers []bbn.BTCHeaderBytes) []*wire.BlockHeader { diff --git a/x/btclightclient/keeper/keeper_test.go b/x/btclightclient/keeper/keeper_test.go index 90ddeaa96..896ebf88a 100644 --- a/x/btclightclient/keeper/keeper_test.go +++ b/x/btclightclient/keeper/keeper_test.go @@ -160,7 +160,7 @@ func FuzzKeeperInsertValidChainExtension(f *testing.F) { extendedChainWork := oldTip.Work.Add(*chainExtensionWork) extendedChainHeight := uint64(uint32(oldTip.Height) + newChainLength) - err := blcKeeper.InsertHeaders(ctx, keepertest.NewBTCHeaderBytesList(chainToInsert)) + err := blcKeeper.InsertHeadersWithHookAndEvents(ctx, keepertest.NewBTCHeaderBytesList(chainToInsert)) require.NoError(t, err) // updated tip @@ -247,7 +247,7 @@ func FuzzKeeperInsertValidBetterChain(f *testing.F) { require.True(t, len(removedBranch) > 0) - err := blcKeeper.InsertHeaders(ctx, keepertest.NewBTCHeaderBytesList(chainToInsert)) + err := blcKeeper.InsertHeadersWithHookAndEvents(ctx, keepertest.NewBTCHeaderBytesList(chainToInsert)) require.NoError(t, err) // updated tip @@ -332,16 +332,16 @@ func FuzzKeeperInsertInvalidChain(f *testing.F) { require.NotNil(t, currentTip) // Inserting nil headers should result with error - errNil := blcKeeper.InsertHeaders(ctx, nil) + errNil := blcKeeper.InsertHeadersWithHookAndEvents(ctx, nil) require.Error(t, errNil) // Inserting empty headers should result with error - errEmpty := blcKeeper.InsertHeaders(ctx, []bbn.BTCHeaderBytes{}) + errEmpty := blcKeeper.InsertHeadersWithHookAndEvents(ctx, []bbn.BTCHeaderBytes{}) require.Error(t, errEmpty) // Inserting header without existing parent should result with error chain := datagen.NewBTCHeaderChainWithLength(r, 0, 0, 10) - errNoParent := blcKeeper.InsertHeaders(ctx, chain.ChainToBytes()[1:]) + errNoParent := blcKeeper.InsertHeadersWithHookAndEvents(ctx, chain.ChainToBytes()[1:]) require.Error(t, errNoParent) require.True(t, errors.Is(errNoParent, types.ErrHeaderParentDoesNotExist)) @@ -358,7 +358,7 @@ func FuzzKeeperInsertInvalidChain(f *testing.F) { // bump the nonce, it should fail validation and tip should not change chainToInsert[3].Nonce = chainToInsert[3].Nonce + 1 - errInvalidHeader := blcKeeper.InsertHeaders(ctx, keepertest.NewBTCHeaderBytesList(chainToInsert)) + errInvalidHeader := blcKeeper.InsertHeadersWithHookAndEvents(ctx, keepertest.NewBTCHeaderBytesList(chainToInsert)) require.Error(t, errInvalidHeader) newTip := blcKeeper.GetTipInfo(ctx) // tip did not change @@ -374,7 +374,7 @@ func FuzzKeeperInsertInvalidChain(f *testing.F) { nil, 1, ) - errWorseChain := blcKeeper.InsertHeaders(ctx, keepertest.NewBTCHeaderBytesList(worseChain)) + errWorseChain := blcKeeper.InsertHeadersWithHookAndEvents(ctx, keepertest.NewBTCHeaderBytesList(worseChain)) require.Error(t, errWorseChain) require.True(t, errors.Is(errWorseChain, types.ErrChainWithNotEnoughWork)) }) @@ -409,13 +409,13 @@ func FuzzKeeperValdateHeaderAtDifficultyAdjustmentBoundaries(f *testing.F) { // this will always fail as last header is at adjustment boundary, but we created // it without adjustment - err := blcKeeper.InsertHeaders(ctx, randomChain.ChainToBytes()) + err := blcKeeper.InsertHeadersWithHookAndEvents(ctx, randomChain.ChainToBytes()) require.Error(t, err) randomChainWithoutLastHeader := randomChain.Headers[:len(randomChain.Headers)-1] chain := keepertest.NewBTCHeaderBytesList(randomChainWithoutLastHeader) // now all headers are valid, and we are below adjustment boundary - err = blcKeeper.InsertHeaders(ctx, chain) + err = blcKeeper.InsertHeadersWithHookAndEvents(ctx, chain) require.NoError(t, err) currentTip := blcKeeper.GetTipInfo(ctx) @@ -429,7 +429,7 @@ func FuzzKeeperValdateHeaderAtDifficultyAdjustmentBoundaries(f *testing.F) { nil, ) // try to insert header at adjustment boundary without adjustment should fail - err = blcKeeper.InsertHeaders(ctx, []bbn.BTCHeaderBytes{bbn.NewBTCHeaderBytesFromBlockHeader(invalidAdjustedHeader)}) + err = blcKeeper.InsertHeadersWithHookAndEvents(ctx, []bbn.BTCHeaderBytes{bbn.NewBTCHeaderBytesFromBlockHeader(invalidAdjustedHeader)}) require.Error(t, err) // Inserting valid adjusted header should succeed @@ -446,7 +446,7 @@ func FuzzKeeperValdateHeaderAtDifficultyAdjustmentBoundaries(f *testing.F) { ) validAdjustedHeaderBytes := bbn.NewBTCHeaderBytesFromBlockHeader(validAdjustedHeader) - err = blcKeeper.InsertHeaders(ctx, []bbn.BTCHeaderBytes{bbn.NewBTCHeaderBytesFromBlockHeader(validAdjustedHeader)}) + err = blcKeeper.InsertHeadersWithHookAndEvents(ctx, []bbn.BTCHeaderBytes{bbn.NewBTCHeaderBytesFromBlockHeader(validAdjustedHeader)}) require.NoError(t, err) newTip := blcKeeper.GetTipInfo(ctx) diff --git a/x/btclightclient/keeper/msg_server.go b/x/btclightclient/keeper/msg_server.go index 90de17942..b40880e5f 100644 --- a/x/btclightclient/keeper/msg_server.go +++ b/x/btclightclient/keeper/msg_server.go @@ -47,7 +47,7 @@ func (m msgServer) InsertHeaders(ctx context.Context, msg *types.MsgInsertHeader return nil, types.ErrUnauthorizedReporter.Wrapf("reporter %s is not authorized to insert headers", reporterAddress) } - err := m.k.InsertHeaders(sdkCtx, msg.Headers) + err := m.k.InsertHeadersWithHookAndEvents(sdkCtx, msg.Headers) if err != nil { return nil, err diff --git a/x/monitor/keeper/grpc_query_test.go b/x/monitor/keeper/grpc_query_test.go index 53ea0862f..9f47095b4 100644 --- a/x/monitor/keeper/grpc_query_test.go +++ b/x/monitor/keeper/grpc_query_test.go @@ -41,7 +41,7 @@ func FuzzQueryEndedEpochBtcHeight(f *testing.F) { 10, ) headerBytes := datagen.HeaderToHeaderBytes(chain) - err := lck.InsertHeaders(ctx, headerBytes) + err := lck.InsertHeadersWithHookAndEvents(ctx, headerBytes) require.NoError(t, err) // go to BeginBlock of block 11, and thus entering epoch 2 @@ -98,7 +98,7 @@ func FuzzQueryReportedCheckpointBtcHeight(f *testing.F) { 10, ) headerBytes := datagen.HeaderToHeaderBytes(chain) - err := lck.InsertHeaders(ctx, headerBytes) + err := lck.InsertHeadersWithHookAndEvents(ctx, headerBytes) require.NoError(t, err) // Add checkpoint diff --git a/x/zoneconcierge/keeper/ibc_packet_btc_timestamp_test.go b/x/zoneconcierge/keeper/ibc_packet_btc_timestamp_test.go index 7a2d1a7c6..014203fe5 100644 --- a/x/zoneconcierge/keeper/ibc_packet_btc_timestamp_test.go +++ b/x/zoneconcierge/keeper/ibc_packet_btc_timestamp_test.go @@ -32,7 +32,7 @@ func genRandomChain( initHeader, uint32(chainLength), ) - err := k.InsertHeaders(ctx, randomChain.ChainToBytes()) + err := k.InsertHeadersWithHookAndEvents(ctx, randomChain.ChainToBytes()) require.NoError(t, err) tip := k.GetTipInfo(ctx) randomChainTipInfo := randomChain.GetTipInfo() diff --git a/x/zoneconcierge/types/btc_timestamp.go b/x/zoneconcierge/types/btc_timestamp.go index c1cde804e..d54b04355 100644 --- a/x/zoneconcierge/types/btc_timestamp.go +++ b/x/zoneconcierge/types/btc_timestamp.go @@ -273,7 +273,7 @@ func (ts *BTCTimestamp) Verify( headerBytes := bbn.NewBTCHeaderBytesFromBlockHeader(headerInfo.Header.ToBlockHeader()) headersBytes = append(headersBytes, headerBytes) } - if err := btclcKeeper.InsertHeaders(ctx, headersBytes); err != nil { + if err := btclcKeeper.InsertHeadersWithHookAndEvents(ctx, headersBytes); err != nil { return err } From 89da3748ff3f29a294585f27d5179b6ed452d958 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 6 Aug 2024 11:19:03 -0300 Subject: [PATCH 37/89] chore: add diskfree --- .github/workflows/ci.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2bd66cedb..c08a4608f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,17 @@ on: - '**' jobs: + free-disk-space: + runs-on: ubuntu-latest + steps: + + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + + lint_test: - uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.2.1 + needs: free-disk-space + uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@remove_go_cache with: run-unit-tests: true run-integration-tests: true From 42a54243c3b2e9cd84ce0d51078e399c14cda3db Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 6 Aug 2024 16:29:26 -0300 Subject: [PATCH 38/89] chore: remove free disk space --- .github/workflows/ci.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d524410d..4d6195d69 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,16 +6,7 @@ on: - '**' jobs: - free-disk-space: - runs-on: ubuntu-latest - steps: - - - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@main - - lint_test: - needs: free-disk-space uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@remove_go_cache secrets: inherit with: From 07398defd70a8f85277ba37858743916cc3de8e3 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 6 Aug 2024 19:30:36 -0300 Subject: [PATCH 39/89] chore: add free disk space --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d6195d69..1d524410d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,16 @@ on: - '**' jobs: + free-disk-space: + runs-on: ubuntu-latest + steps: + + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + + lint_test: + needs: free-disk-space uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@remove_go_cache secrets: inherit with: From 5bc73d26172f2cae0bad941d60c5407709e34782 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Tue, 6 Aug 2024 19:49:41 -0300 Subject: [PATCH 40/89] chore: add free disk --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d524410d..577255e45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,11 +9,9 @@ jobs: free-disk-space: runs-on: ubuntu-latest steps: - - name: Free Disk Space (Ubuntu) uses: jlumbroso/free-disk-space@main - lint_test: needs: free-disk-space uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@remove_go_cache From e090d22e51780751df652dcd467de000d15545dc Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 07:36:34 -0300 Subject: [PATCH 41/89] fix: 60m test-e2e --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 275bdbc5b..7e8b1a721 100644 --- a/Makefile +++ b/Makefile @@ -255,7 +255,7 @@ endif .PHONY: run-tests test test-all $(TEST_TARGETS) test-e2e: build-docker-e2e - go test -mod=readonly -timeout=30m -v $(PACKAGES_E2E) -count=1 --tags=e2e + go test -mod=readonly -timeout=60m -v $(PACKAGES_E2E) -count=1 --tags=e2e test-sim-nondeterminism: @echo "Running non-determinism test..." From be7fddc3859b4a17fbad6c603d16c4fa338cf203 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 08:18:05 -0300 Subject: [PATCH 42/89] chore: disable docker pipeline --- .github/workflows/ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 577255e45..286308638 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: lint_test: needs: free-disk-space - uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@remove_go_cache + uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.2.1 secrets: inherit with: run-unit-tests: true @@ -23,10 +23,10 @@ jobs: integration-tests-command: | sudo make test-e2e - docker_pipeline: - uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.2.1 - secrets: inherit - with: - publish: false - dockerfile: ./contrib/images/babylond/Dockerfile - repoName: babylond \ No newline at end of file + # docker_pipeline: + # uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.2.1 + # secrets: inherit + # with: + # publish: false + # dockerfile: ./contrib/images/babylond/Dockerfile + # repoName: babylond \ No newline at end of file From 4185fcc12a29aad04eacde4b0ec7994785c8b3fe Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 09:54:36 -0300 Subject: [PATCH 43/89] chore: remove template --- .github/workflows/ci.yml | 118 +++++++++++++++++++++++++++++++++------ 1 file changed, 100 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 286308638..4f9cccbab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,26 +7,108 @@ on: jobs: free-disk-space: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Free Disk Space (Ubuntu) uses: jlumbroso/free-disk-space@main + with: + # this might remove tools that are actually needed, + # if set to "true" but frees about 6 GB + tool-cache: true - lint_test: + build: needs: free-disk-space - uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.2.1 - secrets: inherit - with: - run-unit-tests: true - run-integration-tests: true - run-lint: true - integration-tests-command: | - sudo make test-e2e - - # docker_pipeline: - # uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.2.1 - # secrets: inherit - # with: - # publish: false - # dockerfile: ./contrib/images/babylond/Dockerfile - # repoName: babylond \ No newline at end of file + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Print Go environment + run: go env + + - name: Build Application + run: make build + + lint: + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Run Lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.59 + args: --timeout=10m + + unit-tests: + needs: build + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Run Unit Tests + run: | + make test + + integration-tests: + needs: build + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Run Integration Tests + run: sudo make test-e2e + + check-mock-gen: + needs: build + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Run make mock-gen + run: make mock-gen + + - name: Check for uncommitted changes + run: | + if ! git diff --exit-code; then + echo "Uncommitted changes detected. Please run 'make mock-gen' before committing." + exit 1 + fi + + +# docker_pipeline: +# uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.2.1 +# secrets: inherit +# with: +# publish: false +# dockerfile: ./contrib/images/babylond/Dockerfile +# repoName: babylond \ No newline at end of file From 71b4a962c55db7b5f892248542c9ba40996d066c Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 09:59:25 -0300 Subject: [PATCH 44/89] chore: add needs to lint as well --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f9cccbab..a781d864a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,7 @@ jobs: run: make build lint: + needs: build runs-on: ubuntu-22.04 steps: - name: Checkout repository From 9e7893e73e2300385a2da8a7aac9bc60b21afb42 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 09:59:46 -0300 Subject: [PATCH 45/89] chore: remove free-disk --- .github/workflows/ci.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a781d864a..0685a3fc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,18 +6,7 @@ on: - '**' jobs: - free-disk-space: - runs-on: ubuntu-22.04 - steps: - - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@main - with: - # this might remove tools that are actually needed, - # if set to "true" but frees about 6 GB - tool-cache: true - build: - needs: free-disk-space runs-on: ubuntu-22.04 steps: - name: Checkout repository From 7c2de617e5e24ad1521387f45980bf273072e66d Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 10:06:58 -0300 Subject: [PATCH 46/89] fix: make mocks lint --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0685a3fc9..b343291aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,12 +85,12 @@ jobs: go-version: 1.21 - name: Run make mock-gen - run: make mock-gen + run: make mocks - name: Check for uncommitted changes run: | if ! git diff --exit-code; then - echo "Uncommitted changes detected. Please run 'make mock-gen' before committing." + echo "Uncommitted changes detected. Please run 'make mocks' before committing." exit 1 fi From 3407f71bafb2c0522c96a90bc188b2f755f3f763 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 10:08:46 -0300 Subject: [PATCH 47/89] chore: add comment for needs --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b343291aa..6d66a6c14 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ jobs: - name: Build Application run: make build +# needs: build, in other jobs is to utilize the go cache created by build lint: needs: build runs-on: ubuntu-22.04 From ea74d0349668de1910f2427823202790bcaa6347 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 10:11:56 -0300 Subject: [PATCH 48/89] chore: reduce the dockerfile size by only fetch the needed tag --- contrib/images/babylond/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/images/babylond/Dockerfile b/contrib/images/babylond/Dockerfile index 344877e0b..50f7857b8 100644 --- a/contrib/images/babylond/Dockerfile +++ b/contrib/images/babylond/Dockerfile @@ -20,7 +20,7 @@ RUN go mod download COPY ./ /go/src/github.com/babylonlabs-io/babylon/ # If version is set, then checkout this version RUN if [ -n "${VERSION}" ]; then \ - git fetch --all; \ + git fetch origin ${VERSION}; \ git checkout -f ${VERSION}; \ fi From 30b9fd47cef4ff222e8c88c2a4ad3c6d3ac6efe3 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 10:52:25 -0300 Subject: [PATCH 49/89] fix: fetch tag of docker --- contrib/images/babylond/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/images/babylond/Dockerfile b/contrib/images/babylond/Dockerfile index 50f7857b8..f01a13508 100644 --- a/contrib/images/babylond/Dockerfile +++ b/contrib/images/babylond/Dockerfile @@ -20,7 +20,7 @@ RUN go mod download COPY ./ /go/src/github.com/babylonlabs-io/babylon/ # If version is set, then checkout this version RUN if [ -n "${VERSION}" ]; then \ - git fetch origin ${VERSION}; \ + git fetch origin tag ${VERSION}; --no-tags \ git checkout -f ${VERSION}; \ fi From f2a641b506a1a8962d8de2cd28b517ee0b7ba0a1 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 11:05:08 -0300 Subject: [PATCH 50/89] fix: docker build tag --- contrib/images/babylond/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/images/babylond/Dockerfile b/contrib/images/babylond/Dockerfile index f01a13508..71cd8c8bd 100644 --- a/contrib/images/babylond/Dockerfile +++ b/contrib/images/babylond/Dockerfile @@ -20,7 +20,7 @@ RUN go mod download COPY ./ /go/src/github.com/babylonlabs-io/babylon/ # If version is set, then checkout this version RUN if [ -n "${VERSION}" ]; then \ - git fetch origin tag ${VERSION}; --no-tags \ + git fetch origin tag ${VERSION} --no-tags; \ git checkout -f ${VERSION}; \ fi From 36546a9b32ba0e2961d257f9cc980dcfd8879ee6 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 11:34:18 -0300 Subject: [PATCH 51/89] chore: add freespace :/ --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d66a6c14..77541ba19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,14 @@ on: - '**' jobs: + free-disk-space: + runs-on: ubuntu-latest + steps: + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + build: + needs: free-disk-space runs-on: ubuntu-22.04 steps: - name: Checkout repository From 43efd956accfde7d645c5f7fc57546a231ded422 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 15:04:31 -0300 Subject: [PATCH 52/89] chore: reduce dowload of go mods --- Makefile | 2 +- contrib/images/Makefile | 16 ++++-- contrib/images/babylond/Dockerfile | 57 +++++++------------ .../images/e2e-initialization/init.Dockerfile | 31 ++++------ 4 files changed, 45 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 058d5fc9c..eed445275 100644 --- a/Makefile +++ b/Makefile @@ -147,7 +147,7 @@ build: BUILD_ARGS=-o $(BUILDDIR)/ ## Build babylond binary build-linux: ## Build babylond linux version binary GOOS=linux GOARCH=$(if $(findstring aarch64,$(shell uname -m)) || $(findstring arm64,$(shell uname -m)),arm64,amd64) LEDGER_ENABLED=false $(MAKE) build -$(BUILD_TARGETS): go.sum $(BUILDDIR)/ +$(BUILD_TARGETS): $(BUILDDIR)/ go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./... $(BUILDDIR)/: diff --git a/contrib/images/Makefile b/contrib/images/Makefile index beef16916..45f6c057c 100644 --- a/contrib/images/Makefile +++ b/contrib/images/Makefile @@ -9,15 +9,21 @@ babylond: babylond-rmi babylond-e2e: babylond-rmi docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile ${BABYLON_FULL_PATH} \ - --build-arg BUILD_TAGS="e2e" + --build-arg BUILD_TAGS="e2e" --progress=plain +## TODO: once release docker public versions for tags, remove this! babylond-before-upgrade: - docker rmi babylonlabs-io/babylond-before-upgrade 2>/dev/null; true && \ - docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile \ + docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile --progress=plain \ --build-arg VERSION="${BABYLON_VERSION_BEFORE_UPGRADE}" ${BABYLON_FULL_PATH} babylond-rmi: - docker rmi babylonlabs-io/babylond 2>/dev/null; true + docker rmi babylonlabs-io/babylond --force 2>/dev/null; true + +babylond-rmi-upgrade: + docker rmi babylonlabs-io/babylond-before-upgrade --force 2>/dev/null; true + +e2e-init-chain-rmi: + docker rmi babylonlabs-io/babylond-e2e-init-chain --force 2>/dev/null; true e2e-init-chain: @DOCKER_BUILDKIT=1 docker build -t babylonlabs-io/babylond-e2e-init-chain --build-arg E2E_SCRIPT_NAME=chain --platform=linux/x86_64 \ @@ -31,4 +37,4 @@ cosmos-relayer: cosmos-relayer-rmi cosmos-relayer-rmi: docker rmi babylonlabs-io/cosmos-relayer 2>/dev/null; true -.PHONY: all babylond babylond-before-upgrade cosmos-relayer e2e-init-chain babylond-rmi cosmos-relayer-rmi +.PHONY: all babylond babylond-before-upgrade cosmos-relayer e2e-init-chain babylond-rmi babylond-rmi-upgrade cosmos-relayer-rmi diff --git a/contrib/images/babylond/Dockerfile b/contrib/images/babylond/Dockerfile index 344877e0b..7f121ae18 100644 --- a/contrib/images/babylond/Dockerfile +++ b/contrib/images/babylond/Dockerfile @@ -1,58 +1,45 @@ -FROM golang:1.21 AS build-env +FROM golang:1.21 as go-bbn # Version to build. Default is empty ARG VERSION -ARG BUILD_TAGS="" -ARG LEDGER_ENABLED="false" -# Cosmos build options -ARG COSMOS_BUILD_OPTIONS="" - -# Install cli tools for building and final image -RUN apt-get update && apt-get install -y make git bash gcc curl jq - -# Build WORKDIR /go/src/github.com/babylonlabs-io/babylon -# First cache dependencies -COPY go.mod go.sum /go/src/github.com/babylonlabs-io/babylon/ -RUN go mod download -# Then copy everything else COPY ./ /go/src/github.com/babylonlabs-io/babylon/ -# If version is set, then checkout this version + +# Handle if version is set RUN if [ -n "${VERSION}" ]; then \ - git fetch --all; \ + git fetch origin tag ${VERSION} --no-tags; \ git checkout -f ${VERSION}; \ fi +FROM go-bbn as go-bbn-dep + +# Cache mod dependencies +RUN go mod download + +FROM go-bbn-dep as build-env + +ARG BUILD_TAGS="" +ARG LEDGER_ENABLED="false" +ARG COSMOS_BUILD_OPTIONS="" + RUN LEDGER_ENABLED=$LEDGER_ENABLED \ BUILD_TAGS=$BUILD_TAGS \ COSMOS_BUILD_OPTIONS=$COSMOS_BUILD_OPTIONS \ LINK_STATICALLY=false \ make build -FROM debian:bookworm-slim AS run -# Create a user -RUN addgroup --gid 1137 --system babylon && adduser --uid 1137 --gid 1137 --system --home /home/babylon babylon -RUN apt-get update && apt-get install -y bash curl jq wget +FROM debian:bookworm-slim AS wasm-link +ARG WASMVM_VERSION="v2.0.1" + +RUN apt-get update && apt-get install -y wget bash # Label should match your github repo LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/babylond:${VERSION}" -# Install libraries # Cosmwasm - Download correct libwasmvm version -COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/go.mod /tmp -RUN WASMVM_VERSION=$(grep github.com/CosmWasm/wasmvm /tmp/go.mod | cut -d' ' -f2) && \ - wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.$(uname -m).so \ - -O /lib/libwasmvm.$(uname -m).so && \ - # verify checksum - wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \ - sha256sum /lib/libwasmvm.$(uname -m).so | grep $(cat /tmp/checksums.txt | grep libwasmvm.$(uname -m) | cut -d ' ' -f 1) -RUN rm -f /tmp/go.mod +RUN wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.x86_64.so \ + -O /lib/libwasmvm.x86_64.so +FROM wasm-link as final COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/build/babylond /bin/babylond - -# Set home directory and user -WORKDIR /home/babylon -RUN chown -R babylon /home/babylon -RUN chmod g+s /home/babylon -USER babylon diff --git a/contrib/images/e2e-initialization/init.Dockerfile b/contrib/images/e2e-initialization/init.Dockerfile index f457829ed..5026dda51 100644 --- a/contrib/images/e2e-initialization/init.Dockerfile +++ b/contrib/images/e2e-initialization/init.Dockerfile @@ -2,34 +2,25 @@ FROM golang:1.21 as build-env ARG E2E_SCRIPT_NAME -# Install cli tools for building and final image -RUN apt-get update && apt-get install -y make git bash gcc curl jq - +# Copy All WORKDIR /go/src/github.com/babylonlabs-io/babylon - -# First cache dependencies -COPY go.mod go.sum /go/src/github.com/babylonlabs-io/babylon/ -RUN go mod download - -# Copy everything else COPY ./ /go/src/github.com/babylonlabs-io/babylon/ RUN LEDGER_ENABLED=false LINK_STATICALLY=false E2E_SCRIPT_NAME=${E2E_SCRIPT_NAME} make e2e-build-script -FROM debian:bookworm-slim AS run +FROM debian:bookworm-slim AS wasm-link +ARG WASMVM_VERSION="v2.0.1" + +RUN apt-get update && apt-get install -y wget bash -# Create a user -RUN addgroup --gid 1137 --system babylon && adduser --uid 1137 --gid 1137 --system --home /home/babylon babylon -RUN apt-get update && apt-get install -y bash curl jq wget +# Label should match your github repo +LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/babylond:${VERSION}" -COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/go.mod /tmp -RUN WASMVM_VERSION=$(grep github.com/CosmWasm/wasmvm /tmp/go.mod | cut -d' ' -f2) && \ - wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.$(uname -m).so \ - -O /lib/libwasmvm.$(uname -m).so && \ - # verify checksum - wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \ - sha256sum /lib/libwasmvm.$(uname -m).so | grep $(cat /tmp/checksums.txt | grep libwasmvm.$(uname -m) | cut -d ' ' -f 1) +# Cosmwasm - Download correct libwasmvm version +RUN wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.x86_64.so \ + -O /lib/libwasmvm.x86_64.so +FROM wasm-link as final # Args only last for a single build stage - renew ARG E2E_SCRIPT_NAME From a647f8b71c42b3e084d189ce744593ecb3ca1517 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 15:13:14 -0300 Subject: [PATCH 53/89] chore: simplify identifier name --- test/e2e/configurer/factory.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/e2e/configurer/factory.go b/test/e2e/configurer/factory.go index df41dc9a2..a2b74671c 100644 --- a/test/e2e/configurer/factory.go +++ b/test/e2e/configurer/factory.go @@ -1,6 +1,7 @@ package configurer import ( + "strings" "testing" "github.com/babylonlabs-io/babylon/test/e2e/configurer/chain" @@ -114,7 +115,7 @@ var ( // TODO currently only one configuration is available. Consider testing upgrades // when necessary func NewBTCTimestampingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - identifier := t.Name() + identifier := identifierName(t) containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false) if err != nil { return nil, err @@ -131,7 +132,7 @@ func NewBTCTimestampingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configu } func NewIBCTransferConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - identifier := t.Name() + identifier := identifierName(t) containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false) if err != nil { return nil, err @@ -149,7 +150,7 @@ func NewIBCTransferConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, // NewBTCTimestampingPhase2Configurer returns a new Configurer for BTC timestamping service (phase 2). func NewBTCTimestampingPhase2Configurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - identifier := t.Name() + identifier := identifierName(t) containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false) if err != nil { return nil, err @@ -167,7 +168,7 @@ func NewBTCTimestampingPhase2Configurer(t *testing.T, isDebugLogEnabled bool) (C // NewBTCTimestampingPhase2RlyConfigurer returns a new Configurer for BTC timestamping service (phase 2), using the Go relayer (rly). func NewBTCTimestampingPhase2RlyConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - identifier := t.Name() + identifier := identifierName(t) containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, true, false) if err != nil { return nil, err @@ -185,7 +186,7 @@ func NewBTCTimestampingPhase2RlyConfigurer(t *testing.T, isDebugLogEnabled bool) // NewBTCStakingConfigurer returns a new Configurer for BTC staking service func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { - identifier := t.Name() + identifier := identifierName(t) containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false) if err != nil { return nil, err @@ -203,7 +204,7 @@ func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, // NewSoftwareUpgradeConfigurer returns a new Configurer for Software Upgrade testing func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradePath string) (Configurer, error) { - identifier := t.Name() + identifier := identifierName(t) containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, true) if err != nil { return nil, err @@ -220,3 +221,8 @@ func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradeP 0, ), nil } + +func identifierName(t *testing.T) string { + str := strings.ToLower(t.Name()) + return strings.ReplaceAll(str, "/", "-") +} From bf798959772b1b0bfd002de2e0dbf13dcb5b38d3 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 15:18:09 -0300 Subject: [PATCH 54/89] chore: inital parallel --- test/e2e/containers/containers.go | 43 +++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 88f55566d..f10431e3a 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -60,22 +60,22 @@ func NewManager(identifier string, isDebugLogEnabled bool, isCosmosRelayer, isUp } // ExecTxCmd Runs ExecTxCmdWithSuccessString searching for `code: 0` -func (m *Manager) ExecTxCmd(t *testing.T, chainId string, containerName string, command []string) (bytes.Buffer, bytes.Buffer, error) { - return m.ExecTxCmdWithSuccessString(t, chainId, containerName, command, "code: 0") +func (m *Manager) ExecTxCmd(t *testing.T, chainId string, nodeName string, command []string) (bytes.Buffer, bytes.Buffer, error) { + return m.ExecTxCmdWithSuccessString(t, chainId, nodeName, command, "code: 0") } // ExecTxCmdWithSuccessString Runs ExecCmd, with flags for txs added. // namely adding flags `--chain-id={chain-id} -b=block --yes --keyring-backend=test "--log_format=json"`, // and searching for `successStr` -func (m *Manager) ExecTxCmdWithSuccessString(t *testing.T, chainId string, containerName string, command []string, successStr string) (bytes.Buffer, bytes.Buffer, error) { +func (m *Manager) ExecTxCmdWithSuccessString(t *testing.T, chainId string, nodeName string, command []string, successStr string) (bytes.Buffer, bytes.Buffer, error) { allTxArgs := []string{fmt.Sprintf("--chain-id=%s", chainId), "-b=sync", "--yes", "--keyring-backend=test", "--log_format=json", "--home=/home/babylon/babylondata"} txCommand := append(command, allTxArgs...) - return m.ExecCmd(t, containerName, txCommand, successStr) + return m.ExecCmd(t, m.ContainerName(nodeName), txCommand, successStr) } // ExecHermesCmd executes command on the hermes relaer container. func (m *Manager) ExecHermesCmd(t *testing.T, command []string, success string) (bytes.Buffer, bytes.Buffer, error) { - return m.ExecCmd(t, hermesContainerName, command, success) + return m.ExecCmd(t, m.HermesContainerName(), command, success) } // ExecCmd executes command by running it on the node container (specified by containerName) @@ -83,11 +83,11 @@ func (m *Manager) ExecHermesCmd(t *testing.T, command []string, success string) // It is found by checking if stdout or stderr contains the success string anywhere within it. // returns container std out, container std err, and error if any. // An error is returned if the command fails to execute or if the success string is not found in the output. -func (m *Manager) ExecCmd(t *testing.T, containerName string, command []string, success string) (bytes.Buffer, bytes.Buffer, error) { - if _, ok := m.resources[containerName]; !ok { - return bytes.Buffer{}, bytes.Buffer{}, fmt.Errorf("no resource %s found", containerName) +func (m *Manager) ExecCmd(t *testing.T, fullContainerName string, command []string, success string) (bytes.Buffer, bytes.Buffer, error) { + if _, ok := m.resources[fullContainerName]; !ok { + return bytes.Buffer{}, bytes.Buffer{}, fmt.Errorf("no resource %s found", fullContainerName) } - containerId := m.resources[containerName].Container.ID + containerId := m.resources[fullContainerName].Container.ID var ( outBuf bytes.Buffer @@ -164,7 +164,7 @@ func (m *Manager) ExecCmd(t *testing.T, containerName string, command []string, func (m *Manager) RunHermesResource(chainAID, osmoARelayerNodeName, osmoAValMnemonic, chainBID, osmoBRelayerNodeName, osmoBValMnemonic string, hermesCfgPath string) (*dockertest.Resource, error) { hermesResource, err := m.pool.RunWithOptions( &dockertest.RunOptions{ - Name: hermesContainerName, + Name: m.HermesContainerName(), Repository: m.RelayerRepository, Tag: m.RelayerTag, NetworkID: m.network.Network.ID, @@ -200,7 +200,7 @@ func (m *Manager) RunHermesResource(chainAID, osmoARelayerNodeName, osmoAValMnem if err != nil { return nil, err } - m.resources[hermesContainerName] = hermesResource + m.resources[m.HermesContainerName()] = hermesResource return hermesResource, nil } @@ -209,7 +209,7 @@ func (m *Manager) RunHermesResource(chainAID, osmoARelayerNodeName, osmoAValMnem func (m *Manager) RunRlyResource(chainAID, osmoARelayerNodeName, osmoAValMnemonic, chainAIbcPort, chainBID, osmoBRelayerNodeName, osmoBValMnemonic, chainBIbcPort string, rlyCfgPath string) (*dockertest.Resource, error) { rlyResource, err := m.pool.RunWithOptions( &dockertest.RunOptions{ - Name: cosmosRelayerContainerName, + Name: m.CosmosRlyrContainerName(), Repository: m.RelayerRepository, Tag: m.RelayerTag, NetworkID: m.network.Network.ID, @@ -241,7 +241,7 @@ func (m *Manager) RunRlyResource(chainAID, osmoARelayerNodeName, osmoAValMnemoni if err != nil { return nil, err } - m.resources[cosmosRelayerContainerName] = rlyResource + m.resources[m.CosmosRlyrContainerName()] = rlyResource return rlyResource, nil } @@ -387,3 +387,20 @@ func (m *Manager) RunChainInitResource(chainId string, chainVotingPeriod, chainE func (m *Manager) NetworkName() string { return fmt.Sprintf("bbn-testnet-%s", m.identifier) } + +// HermesContainerName returns the hermes container name concatenated with the +// identifier +func (m *Manager) HermesContainerName() string { + return fmt.Sprintf("%s-%s", hermesContainerName, m.identifier) +} + +// CosmosRlyrContainerName returns the cosmos relayer container name +// concatenated with the identifier +func (m *Manager) CosmosRlyrContainerName() string { + return fmt.Sprintf("%s-%s", cosmosRelayerContainerName, m.identifier) +} + +// ContainerName returns the container name concatenated with the identifier +func (m *Manager) ContainerName(nodeName string) string { + return fmt.Sprintf("%s-%s", nodeName, m.identifier) +} From 6dfb5d3997830c5244b22d3e253d5568c7b18ee2 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 15:19:53 -0300 Subject: [PATCH 55/89] chore: disk space free --- .github/workflows/ci.yml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9e2bd5e8..6abf6df98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,16 @@ on: - '**' jobs: + free-disk-space: + runs-on: ubuntu-latest + steps: + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + tool-cache: true + lint_test: + needs: free-disk-space uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.2.1 secrets: inherit with: @@ -15,11 +24,11 @@ jobs: run-lint: true integration-tests-command: | sudo make test-e2e - - docker_pipeline: - uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.2.1 - secrets: inherit - with: - publish: false - dockerfile: ./contrib/images/babylond/Dockerfile - repoName: babylond \ No newline at end of file + + # docker_pipeline: + # uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.2.1 + # secrets: inherit + # with: + # publish: false + # dockerfile: ./contrib/images/babylond/Dockerfile + # repoName: babylond \ No newline at end of file From 4f056d3662eadc738f8438423ea2b5edbf2b9fb7 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 15:26:28 -0300 Subject: [PATCH 56/89] chore: avoid template and reuse dockers --- .github/workflows/ci.yml | 119 +++++++++++++++++++++++++++++++-------- Makefile | 6 +- contrib/images/Makefile | 8 +-- 3 files changed, 102 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6abf6df98..fded7ab07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,29 +6,98 @@ on: - '**' jobs: - free-disk-space: - runs-on: ubuntu-latest + build: + runs-on: ubuntu-22.04 steps: - - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@main - with: - tool-cache: true - - lint_test: - needs: free-disk-space - uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.2.1 - secrets: inherit - with: - run-unit-tests: true - run-integration-tests: true - run-lint: true - integration-tests-command: | - sudo make test-e2e - - # docker_pipeline: - # uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.2.1 - # secrets: inherit - # with: - # publish: false - # dockerfile: ./contrib/images/babylond/Dockerfile - # repoName: babylond \ No newline at end of file + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Print Go environment + run: go env + + - name: Build Application + run: make build + +# needs: build, in other jobs is to utilize the go cache created by build + lint: + needs: build + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Run Lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.59 + args: --timeout=10m + + unit-tests: + needs: build + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Run Unit Tests + run: | + make test + + check-mock-gen: + needs: build + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Run make mock-gen + run: make mocks + + - name: Check for uncommitted changes + run: | + if ! git diff --exit-code; then + echo "Uncommitted changes detected. Please run 'make mocks' before committing." + exit 1 + fi + + build-integration-tests: + needs: build + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build E2E Dockers + run: | + sudo make build-docker-e2e + + run-integration-tests: + needs: build-integration-tests + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run E2E Tests + run: | + sudo make test-e2e-cache \ No newline at end of file diff --git a/Makefile b/Makefile index eed445275..a0c5a9745 100644 --- a/Makefile +++ b/Makefile @@ -254,8 +254,10 @@ endif .PHONY: run-tests test test-all $(TEST_TARGETS) -test-e2e: build-docker-e2e - go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -count=1 --tags=e2e +test-e2e: build-docker-e2e test-e2e-cache + +test-e2e-cache: + go test -mod=readonly -timeout=60m -v $(PACKAGES_E2E) -count=1 --tags=e2e test-sim-nondeterminism: @echo "Running non-determinism test..." diff --git a/contrib/images/Makefile b/contrib/images/Makefile index 45f6c057c..5c9892904 100644 --- a/contrib/images/Makefile +++ b/contrib/images/Makefile @@ -4,16 +4,16 @@ BABYLON_VERSION_BEFORE_UPGRADE ?= v0.9.0 all: babylond cosmos-relayer -babylond: babylond-rmi +babylond: docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile ${BABYLON_FULL_PATH} -babylond-e2e: babylond-rmi +babylond-e2e: docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile ${BABYLON_FULL_PATH} \ - --build-arg BUILD_TAGS="e2e" --progress=plain + --build-arg BUILD_TAGS="e2e" ## TODO: once release docker public versions for tags, remove this! babylond-before-upgrade: - docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile --progress=plain \ + docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile \ --build-arg VERSION="${BABYLON_VERSION_BEFORE_UPGRADE}" ${BABYLON_FULL_PATH} babylond-rmi: From d501d5aa50af81cf7d4edec25e6366f687709e31 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 15:28:11 -0300 Subject: [PATCH 57/89] fix: add concurrency to stop older actions run --- .github/workflows/ci.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fded7ab07..33b246011 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,11 @@ name: ci on: push: branches: - - '**' + - '**' + +concurrency: + group: ci-${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true jobs: build: @@ -98,6 +102,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + - name: Run E2E Tests run: | sudo make test-e2e-cache \ No newline at end of file From 7eea9bcb2e7829c4ff2692b45319dbe572026a2d Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 16:01:29 -0300 Subject: [PATCH 58/89] fix: add docker-login --- .github/workflows/ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33b246011..49104f992 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,12 +88,17 @@ jobs: needs: build runs-on: ubuntu-22.04 steps: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Checkout repository uses: actions/checkout@v4 - - name: Build E2E Dockers run: | - sudo make build-docker-e2e + sudo make build-docker-e2e run-integration-tests: needs: build-integration-tests From c9f9fe92c75fd12ac51a4c994f7a95a4b54f78a6 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 16:55:04 -0300 Subject: [PATCH 59/89] fix: add docker-login to run --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49104f992..273ac6542 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,12 +88,6 @@ jobs: needs: build runs-on: ubuntu-22.04 steps: - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Checkout repository uses: actions/checkout@v4 - name: Build E2E Dockers @@ -104,6 +98,12 @@ jobs: needs: build-integration-tests runs-on: ubuntu-22.04 steps: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Checkout repository uses: actions/checkout@v4 From d9209836ea8a5246550e95ad2d87093211848ccb Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 17:02:39 -0300 Subject: [PATCH 60/89] chore: use identifier in container naming --- test/e2e/containers/containers.go | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index f10431e3a..3e2530601 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -41,22 +41,22 @@ type Manager struct { // NewManager creates a new Manager instance and initializes // all Docker specific utilities. Returns an error if initialization fails. -func NewManager(identifier string, isDebugLogEnabled bool, isCosmosRelayer, isUpgrade bool) (docker *Manager, err error) { - docker = &Manager{ +func NewManager(identifier string, isDebugLogEnabled bool, isCosmosRelayer, isUpgrade bool) (m *Manager, err error) { + m = &Manager{ ImageConfig: NewImageConfig(isCosmosRelayer, isUpgrade), resources: make(map[string]*dockertest.Resource), isDebugLogEnabled: isDebugLogEnabled, identifier: identifier, } - docker.pool, err = dockertest.NewPool("") + m.pool, err = dockertest.NewPool("") if err != nil { return nil, err } - docker.network, err = docker.pool.CreateNetwork("bbn-testnet") + m.network, err = m.pool.CreateNetwork(m.NetworkName()) if err != nil { return nil, err } - return docker, nil + return m, nil } // ExecTxCmd Runs ExecTxCmdWithSuccessString searching for `code: 0` @@ -247,14 +247,14 @@ func (m *Manager) RunRlyResource(chainAID, osmoARelayerNodeName, osmoAValMnemoni // RunNodeResource runs a node container. Assings containerName to the container. // Mounts the container on valConfigDir volume on the running host. Returns the container resource and error if any. -func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir string) (*dockertest.Resource, error) { +func (m *Manager) RunNodeResource(chainId string, nodeName, valCondifDir string) (*dockertest.Resource, error) { pwd, err := os.Getwd() if err != nil { return nil, err } runOpts := &dockertest.RunOptions{ - Name: containerName, + Name: m.ContainerName(nodeName), Repository: m.CurrentRepository, NetworkID: m.network.Network.ID, User: "root:root", @@ -276,7 +276,7 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st return nil, err } - m.resources[containerName] = resource + m.resources[m.ContainerName(nodeName)] = resource return resource, nil } @@ -287,10 +287,10 @@ func (m *Manager) PurgeResource(resource *dockertest.Resource) error { } // GetNodeResource returns the node resource for containerName. -func (m *Manager) GetNodeResource(containerName string) (*dockertest.Resource, error) { - resource, exists := m.resources[containerName] +func (m *Manager) GetNodeResource(nodeName string) (*dockertest.Resource, error) { + resource, exists := m.resources[m.ContainerName(nodeName)] if !exists { - return nil, fmt.Errorf("node resource not found: container name: %s", containerName) + return nil, fmt.Errorf("node resource not found: container name: %s", nodeName) } return resource, nil } @@ -299,8 +299,8 @@ func (m *Manager) GetNodeResource(containerName string) (*dockertest.Resource, e // necessary to connect to the portId exposed inside the container. // The container is determined by containerName. // Returns the host-port or error if any. -func (m *Manager) GetHostPort(containerName string, portId string) (string, error) { - resource, err := m.GetNodeResource(containerName) +func (m *Manager) GetHostPort(nodeName string, portId string) (string, error) { + resource, err := m.GetNodeResource(nodeName) if err != nil { return "", err } @@ -309,8 +309,8 @@ func (m *Manager) GetHostPort(containerName string, portId string) (string, erro // RemoveNodeResource removes a node container specified by containerName. // Returns error if any. -func (m *Manager) RemoveNodeResource(containerName string) error { - resource, err := m.GetNodeResource(containerName) +func (m *Manager) RemoveNodeResource(nodeName string) error { + resource, err := m.GetNodeResource(nodeName) if err != nil { return err } @@ -320,7 +320,7 @@ func (m *Manager) RemoveNodeResource(containerName string) error { if err := m.pool.Client.RemoveContainer(opts); err != nil { return err } - delete(m.resources, containerName) + delete(m.resources, m.ContainerName(nodeName)) return nil } From 5bbdd604b163752a0054112cc0af689d8e0412ef Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 17:20:50 -0300 Subject: [PATCH 61/89] tryfix: build and run e2e --- .github/workflows/ci.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 273ac6542..5c2dcc143 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,7 @@ jobs: exit 1 fi - build-integration-tests: + build-run-integration-tests: needs: build runs-on: ubuntu-22.04 steps: @@ -94,19 +94,12 @@ jobs: run: | sudo make build-docker-e2e - run-integration-tests: - needs: build-integration-tests - runs-on: ubuntu-22.04 - steps: - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Checkout repository - uses: actions/checkout@v4 - - name: Set up Go uses: actions/setup-go@v5 with: @@ -114,4 +107,4 @@ jobs: - name: Run E2E Tests run: | - sudo make test-e2e-cache \ No newline at end of file + sudo make test-e2e-cache From 5a034d264662ba347148fb6f69d6aed9035858ff Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 21:54:03 -0300 Subject: [PATCH 62/89] chore: add artifacts to run TestBTCTimestampingTestSuite separate --- .github/workflows/ci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ Makefile | 23 ++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c2dcc143..fed0c3c25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,46 @@ jobs: exit 1 fi + + e2e-docker-build-babylon: + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Build docker babylond + run: | + make -C contrib/images babylond + - name: Docker save babylon + run: | + docker save -o /tmp/docker-babylonlabs.tar.gz babylonlabs-io/babylond:latest + + - name: Upload babylon artifact + uses: actions/upload-artifact@v4 + with: + name: babylond-${{ github.sha }} # so it renovates at every new sha + path: /tmp/docker-babylonlabs.tar.gz + + e2e-run-btc-timestamping: + needs: e2e-docker-build-babylon + 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/docker-babylonlabs.tar.gz + + - name: Docker load babylond + run: | + docker load < /tmp/docker-babylonlabs.tar.gz + + - name: Run e2e TestBTCTimestampingTestSuite + run: | + make test-e2e-cache-btc-timestamping + build-run-integration-tests: needs: build runs-on: ubuntu-22.04 diff --git a/Makefile b/Makefile index a0c5a9745..89a298b85 100644 --- a/Makefile +++ b/Makefile @@ -257,7 +257,28 @@ endif test-e2e: build-docker-e2e test-e2e-cache test-e2e-cache: - go test -mod=readonly -timeout=60m -v $(PACKAGES_E2E) -count=1 --tags=e2e + go test -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e + +test-e2e-cache-ibc-transfer: + go test -run TestIBCTranferTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e + +test-e2e-cache-btc-timestamping: + go test -run TestBTCTimestampingTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e + +test-e2e-cache-btc-timestamping-phase-2-hermes: + go test -run TestBTCTimestampingPhase2HermesTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e + +test-e2e-cache-btc-timestamping-phase-2-rly: + go test -run TestBTCTimestampingPhase2RlyTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e + +test-e2e-cache-btc-staking: + go test -run TestBTCStakingTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e + +test-e2e-cache-upgrade-vanilla: + go test -run TestSoftwareUpgradeTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e + +test-e2e-cache-upgrade-signet-launch: + go test -run TestSoftwareUpgradeSignetLaunchTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e test-sim-nondeterminism: @echo "Running non-determinism test..." From bbcfebf9fdb253a00ede21e70321836f015b82b1 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 21:54:19 -0300 Subject: [PATCH 63/89] chore: add need for unit test --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fed0c3c25..5d4f0ef50 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -104,7 +104,7 @@ jobs: path: /tmp/docker-babylonlabs.tar.gz e2e-run-btc-timestamping: - needs: e2e-docker-build-babylon + needs: [e2e-docker-build-babylon, unit-tests] runs-on: ubuntu-22.04 steps: - name: Checkout repository From b4c03b1f787823de13e699c28b360b5e40825df9 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 22:09:29 -0300 Subject: [PATCH 64/89] tryfix: add e2e-run-upgrade-vanilla --- .github/workflows/ci.yml | 51 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d4f0ef50..b8611f52c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,9 @@ jobs: exit 1 fi +############################################################################### +### E2E ### +############################################################################### e2e-docker-build-babylon: runs-on: ubuntu-22.04 @@ -95,13 +98,30 @@ jobs: make -C contrib/images babylond - name: Docker save babylon run: | - docker save -o /tmp/docker-babylonlabs.tar.gz babylonlabs-io/babylond:latest + docker save -o /tmp/docker-babylond.tar.gz babylonlabs-io/babylond:latest - name: Upload babylon artifact uses: actions/upload-artifact@v4 with: name: babylond-${{ github.sha }} # so it renovates at every new sha - path: /tmp/docker-babylonlabs.tar.gz + path: /tmp/docker-babylond.tar.gz + + e2e-docker-build-babylon-before-upgrade: + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Build docker babylond-before-upgrade + run: | + make -C contrib/images babylond-before-upgrade + - name: Docker save babylond-before-upgrade + run: | + docker save -o /tmp/docker-babylond-before-upgrade.tar.gz babylonlabs-io/babylond-before-upgrade:latest + - name: Upload babylond-before-upgrade artifact + uses: actions/upload-artifact@v4 + with: + name: babylond-before-upgrade + path: /tmp/docker-babylond-before-upgrade.tar.gz e2e-run-btc-timestamping: needs: [e2e-docker-build-babylon, unit-tests] @@ -114,16 +134,39 @@ jobs: uses: actions/download-artifact@v4 with: name: babylond-${{ github.sha }} - path: /tmp/docker-babylonlabs.tar.gz - name: Docker load babylond run: | - docker load < /tmp/docker-babylonlabs.tar.gz + docker load < /tmp/docker-babylond.tar.gz - name: Run e2e TestBTCTimestampingTestSuite run: | make test-e2e-cache-btc-timestamping + e2e-run-upgrade-vanilla: + needs: [e2e-docker-build-babylon, e2e-docker-build-babylon-before-upgrade] + 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 }} + - name: Download babylond-before-upgrade artifact + uses: actions/download-artifact@v4 + with: + name: babylond-before-upgrade + - 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: Run e2e TestSoftwareUpgradeTestSuite + run: | + make test-e2e-cache-upgrade-vanilla + build-run-integration-tests: needs: build runs-on: ubuntu-22.04 From 3e7695d1aad561380aa924f747061aff3a4bf088 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 22:20:14 -0300 Subject: [PATCH 65/89] tryfix: docker load to /tmp --- .github/workflows/ci.yml | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8611f52c..e0586cbdc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,6 @@ jobs: - name: Docker save babylon run: | docker save -o /tmp/docker-babylond.tar.gz babylonlabs-io/babylond:latest - - name: Upload babylon artifact uses: actions/upload-artifact@v4 with: @@ -123,22 +122,45 @@ jobs: name: babylond-before-upgrade path: /tmp/docker-babylond-before-upgrade.tar.gz + e2e-run-ibc-transfer: + needs: [e2e-docker-build-babylon] + 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: Docker load babylond + run: | + docker load < /tmp/docker-babylond.tar.gz + - name: Login to Docker Hub # load hermes + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Run e2e TestIBCTranferTestSuite + run: | + make test-e2e-cache-ibc-transfer + e2e-run-btc-timestamping: needs: [e2e-docker-build-babylon, unit-tests] 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: Docker load babylond run: | + ls -la + ls -la /tmp docker load < /tmp/docker-babylond.tar.gz - - name: Run e2e TestBTCTimestampingTestSuite run: | make test-e2e-cache-btc-timestamping @@ -153,10 +175,12 @@ jobs: 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: Docker load babylond run: | docker load < /tmp/docker-babylond.tar.gz From b2207a5192f07738d30edfa36dab7315a6456e20 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 22:35:46 -0300 Subject: [PATCH 66/89] chore: add check if artifact exists --- .github/workflows/ci.yml | 51 +++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0586cbdc..e6291cd4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,13 +108,18 @@ jobs: e2e-docker-build-babylon-before-upgrade: runs-on: ubuntu-22.04 steps: + - name: Artifact babylond-before-upgrade exists + uses: xSAVIKx/artifact-exists-action@v0 + id: check-babylond-before-upgrade + with: + name: babylond-before-upgrade + - name: Checkout repository uses: actions/checkout@v4 - - name: Build docker babylond-before-upgrade + - name: Build docker and save babylond-before-upgrade + if: steps.check-babylond-before-upgrade.outputs.exists == 'false' run: | make -C contrib/images babylond-before-upgrade - - name: Docker save babylond-before-upgrade - run: | docker save -o /tmp/docker-babylond-before-upgrade.tar.gz babylonlabs-io/babylond-before-upgrade:latest - name: Upload babylond-before-upgrade artifact uses: actions/upload-artifact@v4 @@ -122,6 +127,28 @@ jobs: name: babylond-before-upgrade path: /tmp/docker-babylond-before-upgrade.tar.gz + e2e-docker-build-e2e-init-chain: + runs-on: ubuntu-22.04 + steps: + - name: Artifact init-chain exists + uses: xSAVIKx/artifact-exists-action@v0 + id: check-init-chain + with: + name: init-chain + + - name: Checkout repository + uses: actions/checkout@v4 + - name: Build docker and save init-chain + if: steps.check-init-chain.outputs.exists == 'false' + run: | + make -C contrib/images init-chain + docker save -o /tmp/docker-init-chain.tar.gz babylonlabs-io/babylond-e2e-init-chain:latest + - name: Upload init-chain artifact + uses: actions/upload-artifact@v4 + with: + name: init-chain + path: /tmp/docker-init-chain.tar.gz + e2e-run-ibc-transfer: needs: [e2e-docker-build-babylon] runs-on: ubuntu-22.04 @@ -143,10 +170,10 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Run e2e TestIBCTranferTestSuite run: | - make test-e2e-cache-ibc-transfer + sudo make test-e2e-cache-ibc-transfer e2e-run-btc-timestamping: - needs: [e2e-docker-build-babylon, unit-tests] + needs: [e2e-docker-build-babylon] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -163,10 +190,10 @@ jobs: docker load < /tmp/docker-babylond.tar.gz - name: Run e2e TestBTCTimestampingTestSuite run: | - make test-e2e-cache-btc-timestamping + sudo make test-e2e-cache-btc-timestamping e2e-run-upgrade-vanilla: - needs: [e2e-docker-build-babylon, e2e-docker-build-babylon-before-upgrade] + 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 @@ -181,15 +208,23 @@ jobs: 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: Run e2e TestSoftwareUpgradeTestSuite run: | - make test-e2e-cache-upgrade-vanilla + sudo make test-e2e-cache-upgrade-vanilla build-run-integration-tests: needs: build From d4c4122d0933089591896fdc6caf74f98a8eb698 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 22:37:12 -0300 Subject: [PATCH 67/89] fix: e2e init chain --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6291cd4e..402876dc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -141,7 +141,7 @@ jobs: - name: Build docker and save init-chain if: steps.check-init-chain.outputs.exists == 'false' run: | - make -C contrib/images init-chain + make -C contrib/images e2e-init-chain docker save -o /tmp/docker-init-chain.tar.gz babylonlabs-io/babylond-e2e-init-chain:latest - name: Upload init-chain artifact uses: actions/upload-artifact@v4 From 29dadd7832e445d2c9a555d3ea340fedc87d7a21 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 22:43:22 -0300 Subject: [PATCH 68/89] feat: add run of test-e2e-cache-btc-timestamping-phase-2-hermes --- .github/workflows/ci.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 402876dc7..1831eff08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,6 +126,7 @@ jobs: with: name: babylond-before-upgrade path: /tmp/docker-babylond-before-upgrade.tar.gz + retention-days: 90 e2e-docker-build-e2e-init-chain: runs-on: ubuntu-22.04 @@ -148,6 +149,7 @@ jobs: with: name: init-chain path: /tmp/docker-init-chain.tar.gz + retention-days: 90 e2e-run-ibc-transfer: needs: [e2e-docker-build-babylon] @@ -192,6 +194,29 @@ jobs: run: | sudo make test-e2e-cache-btc-timestamping + e2e-run-btc-timestamping-phase-2-hermes: + needs: [e2e-docker-build-babylon] + 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: Docker load babylond + run: | + docker load < /tmp/docker-babylond.tar.gz + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Run e2e TestBTCTimestampingPhase2HermesTestSuite + run: | + sudo make test-e2e-cache-btc-timestamping-phase-2-hermes + e2e-run-upgrade-vanilla: needs: [e2e-docker-build-babylon, e2e-docker-build-babylon-before-upgrade, e2e-docker-build-e2e-init-chain] runs-on: ubuntu-22.04 From 1d49c9add8be80c1c7a56adaeefb1d05619f7015 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 22:50:33 -0300 Subject: [PATCH 69/89] chore: add run for e2e btc staking --- .github/workflows/ci.yml | 49 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1831eff08..cfb4d16a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -175,7 +175,7 @@ jobs: sudo make test-e2e-cache-ibc-transfer e2e-run-btc-timestamping: - needs: [e2e-docker-build-babylon] + needs: [e2e-docker-build-babylon, build] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -187,9 +187,11 @@ jobs: path: /tmp - name: Docker load babylond run: | - ls -la - ls -la /tmp docker load < /tmp/docker-babylond.tar.gz + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 - name: Run e2e TestBTCTimestampingTestSuite run: | sudo make test-e2e-cache-btc-timestamping @@ -217,6 +219,47 @@ jobs: run: | sudo make test-e2e-cache-btc-timestamping-phase-2-hermes + e2e-run-btc-timestamping-phase-2-rly: + needs: [e2e-docker-build-babylon] + 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: Docker load babylond + run: | + docker load < /tmp/docker-babylond.tar.gz + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Run e2e TestBTCTimestampingPhase2RlyTestSuite + run: | + sudo make test-e2e-cache-btc-timestamping-phase-2-rly + + e2e-run-btc-staking: + needs: [e2e-docker-build-babylon] + 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: Docker load babylond + run: | + docker load < /tmp/docker-babylond.tar.gz + - name: Run e2e TestBTCStakingTestSuite + run: | + sudo make test-e2e-cache-btc-staking + e2e-run-upgrade-vanilla: needs: [e2e-docker-build-babylon, e2e-docker-build-babylon-before-upgrade, e2e-docker-build-e2e-init-chain] runs-on: ubuntu-22.04 From fa287f244add9d0c1a2e6a961620e40f10214878 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 22:52:32 -0300 Subject: [PATCH 70/89] chore: update go cache name --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cfb4d16a8..d6813b34c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -188,7 +188,7 @@ jobs: - name: Docker load babylond run: | docker load < /tmp/docker-babylond.tar.gz - - name: Set up Go + - name: Cache Go uses: actions/setup-go@v5 with: go-version: 1.21 From 7fcfcbf2928015942b00924bffa4ea7261a3a237 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 22:53:22 -0300 Subject: [PATCH 71/89] chore: remove upgrade e2e signet launch --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index 89a298b85..170ad1640 100644 --- a/Makefile +++ b/Makefile @@ -277,9 +277,6 @@ 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-launch: - 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 \ From 1a54e90b8aac87fc68003caba1e282351cf8c489 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 23:01:28 -0300 Subject: [PATCH 72/89] chore: remove sudo from make test-e2e-cache-btc-timestamping --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6813b34c..23a7e0dc0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -113,7 +113,6 @@ jobs: id: check-babylond-before-upgrade with: name: babylond-before-upgrade - - name: Checkout repository uses: actions/checkout@v4 - name: Build docker and save babylond-before-upgrade @@ -194,7 +193,7 @@ jobs: go-version: 1.21 - name: Run e2e TestBTCTimestampingTestSuite run: | - sudo make test-e2e-cache-btc-timestamping + make test-e2e-cache-btc-timestamping e2e-run-btc-timestamping-phase-2-hermes: needs: [e2e-docker-build-babylon] From 36d658440593a4e9cf92aa8e2d21a0e3caf9f188 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 23:21:53 -0300 Subject: [PATCH 73/89] fix: remove sudo to use cache from golang --- .github/workflows/ci.yml | 63 ++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23a7e0dc0..ecd31611f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,7 +108,7 @@ jobs: e2e-docker-build-babylon-before-upgrade: runs-on: ubuntu-22.04 steps: - - name: Artifact babylond-before-upgrade exists + - name: Artifact babylond-before-upgrade exists # TODO: check why it doesn't work to load from older workflow runs .-. uses: xSAVIKx/artifact-exists-action@v0 id: check-babylond-before-upgrade with: @@ -151,7 +151,7 @@ jobs: retention-days: 90 e2e-run-ibc-transfer: - needs: [e2e-docker-build-babylon] + needs: [e2e-docker-build-babylon, build] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -169,9 +169,13 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Cache Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 - name: Run e2e TestIBCTranferTestSuite run: | - sudo make test-e2e-cache-ibc-transfer + make test-e2e-cache-ibc-transfer e2e-run-btc-timestamping: needs: [e2e-docker-build-babylon, build] @@ -196,7 +200,7 @@ jobs: make test-e2e-cache-btc-timestamping e2e-run-btc-timestamping-phase-2-hermes: - needs: [e2e-docker-build-babylon] + needs: [e2e-docker-build-babylon, build] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -214,12 +218,16 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Cache Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 - name: Run e2e TestBTCTimestampingPhase2HermesTestSuite run: | - sudo make test-e2e-cache-btc-timestamping-phase-2-hermes + make test-e2e-cache-btc-timestamping-phase-2-hermes e2e-run-btc-timestamping-phase-2-rly: - needs: [e2e-docker-build-babylon] + needs: [e2e-docker-build-babylon, build] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -237,12 +245,16 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Cache Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 - name: Run e2e TestBTCTimestampingPhase2RlyTestSuite run: | - sudo make test-e2e-cache-btc-timestamping-phase-2-rly + make test-e2e-cache-btc-timestamping-phase-2-rly e2e-run-btc-staking: - needs: [e2e-docker-build-babylon] + needs: [e2e-docker-build-babylon, build] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -255,12 +267,16 @@ jobs: - name: Docker load babylond run: | docker load < /tmp/docker-babylond.tar.gz + - name: Cache Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 - name: Run e2e TestBTCStakingTestSuite run: | - sudo make test-e2e-cache-btc-staking + make test-e2e-cache-btc-staking e2e-run-upgrade-vanilla: - needs: [e2e-docker-build-babylon, e2e-docker-build-babylon-before-upgrade, e2e-docker-build-e2e-init-chain] + needs: [e2e-docker-build-babylon, e2e-docker-build-babylon-before-upgrade, e2e-docker-build-e2e-init-chain, build] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -289,31 +305,10 @@ jobs: - name: Docker load init chain run: | docker load < /tmp/docker-init-chain.tar.gz - - name: Run e2e TestSoftwareUpgradeTestSuite - run: | - sudo make test-e2e-cache-upgrade-vanilla - - build-run-integration-tests: - needs: build - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Build E2E Dockers - run: | - sudo make build-docker-e2e - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Set up Go + - name: Cache Go uses: actions/setup-go@v5 with: go-version: 1.21 - - - name: Run E2E Tests + - name: Run e2e TestSoftwareUpgradeTestSuite run: | - sudo make test-e2e-cache + make test-e2e-cache-upgrade-vanilla \ No newline at end of file From 017aced1e029605d20231a072e244968b547ad8a Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 23:22:38 -0300 Subject: [PATCH 74/89] chore: remove require no error on clear resources due to unlinkat /tmp/bbn-e2e-testnet-2820217771/bbn-test-a/bbn-test-a-node-babylon-default-a-2/ibc_08-wasm/state/wasm: permission denied --- test/e2e/btc_staking_e2e_test.go | 4 +++- test/e2e/btc_timestamping_e2e_test.go | 4 +++- test/e2e/btc_timestamping_phase2_hermes_test.go | 4 +++- test/e2e/btc_timestamping_phase2_rly_test.go | 4 +++- test/e2e/containers/containers.go | 10 +++++++--- test/e2e/ibc_transfer_e2e_test.go | 4 +++- test/e2e/software_upgrade_e2e_test.go | 4 +++- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/test/e2e/btc_staking_e2e_test.go b/test/e2e/btc_staking_e2e_test.go index 05c97395e..f4f67a203 100644 --- a/test/e2e/btc_staking_e2e_test.go +++ b/test/e2e/btc_staking_e2e_test.go @@ -68,7 +68,9 @@ func (s *BTCStakingTestSuite) SetupSuite() { func (s *BTCStakingTestSuite) TearDownSuite() { err := s.configurer.ClearResources() - s.Require().NoError(err) + if err != nil { + s.T().Logf("error to clear resources %s", err.Error()) + } } // TestCreateFinalityProviderAndDelegation is an end-to-end test for diff --git a/test/e2e/btc_timestamping_e2e_test.go b/test/e2e/btc_timestamping_e2e_test.go index 6b8282311..8884209cc 100644 --- a/test/e2e/btc_timestamping_e2e_test.go +++ b/test/e2e/btc_timestamping_e2e_test.go @@ -50,7 +50,9 @@ func (s *BTCTimestampingTestSuite) SetupSuite() { func (s *BTCTimestampingTestSuite) TearDownSuite() { err := s.configurer.ClearResources() - s.Require().NoError(err) + if err != nil { + s.T().Logf("error to clear resources %s", err.Error()) + } } // Most simple test, just checking that two chains are up and connected through diff --git a/test/e2e/btc_timestamping_phase2_hermes_test.go b/test/e2e/btc_timestamping_phase2_hermes_test.go index cfae910f4..b8eb6a1e8 100644 --- a/test/e2e/btc_timestamping_phase2_hermes_test.go +++ b/test/e2e/btc_timestamping_phase2_hermes_test.go @@ -44,7 +44,9 @@ func (s *BTCTimestampingPhase2HermesTestSuite) SetupSuite() { func (s *BTCTimestampingPhase2HermesTestSuite) TearDownSuite() { err := s.configurer.ClearResources() - s.Require().NoError(err) + if err != nil { + s.T().Logf("error to clear resources %s", err.Error()) + } } func (s *BTCTimestampingPhase2HermesTestSuite) Test1IbcCheckpointingPhase2Hermes() { diff --git a/test/e2e/btc_timestamping_phase2_rly_test.go b/test/e2e/btc_timestamping_phase2_rly_test.go index 091eabc06..7dc31959e 100644 --- a/test/e2e/btc_timestamping_phase2_rly_test.go +++ b/test/e2e/btc_timestamping_phase2_rly_test.go @@ -44,7 +44,9 @@ func (s *BTCTimestampingPhase2RlyTestSuite) SetupSuite() { func (s *BTCTimestampingPhase2RlyTestSuite) TearDownSuite() { err := s.configurer.ClearResources() - s.Require().NoError(err) + if err != nil { + s.T().Logf("error to clear resources %s", err.Error()) + } } func (s *BTCTimestampingPhase2RlyTestSuite) Test1IbcCheckpointingPhase2Rly() { diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 88f55566d..616ee6b6e 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -3,6 +3,7 @@ package containers import ( "bytes" "context" + "errors" "fmt" "os" "regexp" @@ -334,11 +335,14 @@ func (m *Manager) ClearResources() (e error) { }) } - if err := g.Wait(); err != nil { - return err + // TODO: fix error to delete wasm + // unlinkat /tmp/bbn-e2e-testnet-2820217771/bbn-test-a/bbn-test-a-node-babylon-default-a-2/ibc_08-wasm/state/wasm: permission denied + err := g.Wait() + if err != nil { + fmt.Printf("error to clear resources %s", err.Error()) } - return m.pool.RemoveNetwork(m.network) + return errors.Join(err, m.pool.RemoveNetwork(m.network)) } func noRestart(config *docker.HostConfig) { diff --git a/test/e2e/ibc_transfer_e2e_test.go b/test/e2e/ibc_transfer_e2e_test.go index 7e3597f64..921026dce 100644 --- a/test/e2e/ibc_transfer_e2e_test.go +++ b/test/e2e/ibc_transfer_e2e_test.go @@ -34,7 +34,9 @@ func (s *IBCTransferTestSuite) SetupSuite() { func (s *IBCTransferTestSuite) TearDownSuite() { err := s.configurer.ClearResources() - s.Require().NoError(err) + if err != nil { + s.T().Logf("error to clear resources %s", err.Error()) + } } func (s *IBCTransferTestSuite) Test1IBCTransfer() { diff --git a/test/e2e/software_upgrade_e2e_test.go b/test/e2e/software_upgrade_e2e_test.go index 3cac9f9c9..8018065d8 100644 --- a/test/e2e/software_upgrade_e2e_test.go +++ b/test/e2e/software_upgrade_e2e_test.go @@ -27,7 +27,9 @@ func (s *SoftwareUpgradeVanillaTestSuite) SetupSuite() { func (s *SoftwareUpgradeVanillaTestSuite) TearDownSuite() { err := s.configurer.ClearResources() - s.Require().NoError(err) + if err != nil { + s.T().Logf("error to clear resources %s", err.Error()) + } } // TestUpgradeVanilla only checks that new fp was added. From 59eb0d74c1ec586bee7987153a463aabb462701d Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 7 Aug 2024 23:59:22 -0300 Subject: [PATCH 75/89] chore: add identifier for each run --- test/e2e/configurer/factory.go | 38 +++++++++++++++++++++++-------- test/e2e/containers/containers.go | 27 +++++++++------------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/test/e2e/configurer/factory.go b/test/e2e/configurer/factory.go index a2b74671c..682109b1d 100644 --- a/test/e2e/configurer/factory.go +++ b/test/e2e/configurer/factory.go @@ -1,6 +1,7 @@ package configurer import ( + "fmt" "strings" "testing" @@ -123,8 +124,8 @@ func NewBTCTimestampingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configu return NewCurrentBranchConfigurer(t, []*chain.Config{ - chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, ibcConfigChainA), - chain.New(t, containerManager, initialization.ChainBID, validatorConfigsChainB, ibcConfigChainB), + chain.New(t, containerManager, initialization.ChainAID, updateNodeConfigNameWithIdentifier(validatorConfigsChainA, identifier), ibcConfigChainA), + chain.New(t, containerManager, initialization.ChainBID, updateNodeConfigNameWithIdentifier(validatorConfigsChainB, identifier), ibcConfigChainB), }, withIBC(baseSetup), // base set up with IBC containerManager, @@ -140,8 +141,8 @@ func NewIBCTransferConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, return NewCurrentBranchConfigurer(t, []*chain.Config{ - chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, ibcConfigChainA), - chain.New(t, containerManager, initialization.ChainBID, validatorConfigsChainB, ibcConfigChainB), + chain.New(t, containerManager, initialization.ChainAID, updateNodeConfigNameWithIdentifier(validatorConfigsChainA, identifier), ibcConfigChainA), + chain.New(t, containerManager, initialization.ChainBID, updateNodeConfigNameWithIdentifier(validatorConfigsChainB, identifier), ibcConfigChainB), }, withIBCTransferChannel(baseSetup), // base set up with IBC containerManager, @@ -158,8 +159,8 @@ func NewBTCTimestampingPhase2Configurer(t *testing.T, isDebugLogEnabled bool) (C return NewCurrentBranchConfigurer(t, []*chain.Config{ - chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, ibcConfigChainA), - chain.New(t, containerManager, initialization.ChainBID, validatorConfigsChainB, ibcConfigChainB), + chain.New(t, containerManager, initialization.ChainAID, updateNodeConfigNameWithIdentifier(validatorConfigsChainA, identifier), ibcConfigChainA), + chain.New(t, containerManager, initialization.ChainBID, updateNodeConfigNameWithIdentifier(validatorConfigsChainB, identifier), ibcConfigChainB), }, withPhase2IBC(baseSetup), // IBC setup (requires contract address) containerManager, @@ -176,8 +177,8 @@ func NewBTCTimestampingPhase2RlyConfigurer(t *testing.T, isDebugLogEnabled bool) return NewCurrentBranchConfigurer(t, []*chain.Config{ - chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, ibcConfigChainA), - chain.New(t, containerManager, initialization.ChainBID, validatorConfigsChainB, ibcConfigChainB), + chain.New(t, containerManager, initialization.ChainAID, updateNodeConfigNameWithIdentifier(validatorConfigsChainA, identifier), ibcConfigChainA), + chain.New(t, containerManager, initialization.ChainBID, updateNodeConfigNameWithIdentifier(validatorConfigsChainB, identifier), ibcConfigChainB), }, withPhase2RlyIBC(baseSetup), // IBC setup with wasmd and Go relayer containerManager, @@ -195,7 +196,7 @@ func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, return NewCurrentBranchConfigurer(t, []*chain.Config{ // we only need 1 chain for testing BTC staking - chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, nil), + chain.New(t, containerManager, initialization.ChainAID, updateNodeConfigNameWithIdentifier(validatorConfigsChainA, identifier), nil), }, baseSetup, // base set up containerManager, @@ -212,8 +213,9 @@ func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradeP return NewUpgradeConfigurer(t, []*chain.Config{ + // we only need 1 chain for testing upgrade - chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, nil), + chain.New(t, containerManager, initialization.ChainAID, updateNodeConfigNameWithIdentifier(validatorConfigsChainA, identifier), nil), }, withUpgrade(baseSetup), // base set up with upgrade containerManager, @@ -226,3 +228,19 @@ func identifierName(t *testing.T) string { str := strings.ToLower(t.Name()) return strings.ReplaceAll(str, "/", "-") } + +func updateNodeConfigNameWithIdentifier(cfgs []*initialization.NodeConfig, identifier string) []*initialization.NodeConfig { + result := make([]*initialization.NodeConfig, len(cfgs)) + for i, cfg := range cfgs { + result[i] = &initialization.NodeConfig{ + Name: fmt.Sprintf("%s-%s", cfg.Name, identifier), + Pruning: cfg.Pruning, + PruningKeepRecent: cfg.PruningKeepRecent, + PruningInterval: cfg.PruningInterval, + SnapshotInterval: cfg.SnapshotInterval, + SnapshotKeepRecent: cfg.SnapshotKeepRecent, + IsValidator: cfg.IsValidator, + } + } + return result +} diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index b42b4e7c5..143afbb80 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -68,10 +68,10 @@ func (m *Manager) ExecTxCmd(t *testing.T, chainId string, nodeName string, comma // ExecTxCmdWithSuccessString Runs ExecCmd, with flags for txs added. // namely adding flags `--chain-id={chain-id} -b=block --yes --keyring-backend=test "--log_format=json"`, // and searching for `successStr` -func (m *Manager) ExecTxCmdWithSuccessString(t *testing.T, chainId string, nodeName string, command []string, successStr string) (bytes.Buffer, bytes.Buffer, error) { +func (m *Manager) ExecTxCmdWithSuccessString(t *testing.T, chainId string, containerName string, command []string, successStr string) (bytes.Buffer, bytes.Buffer, error) { allTxArgs := []string{fmt.Sprintf("--chain-id=%s", chainId), "-b=sync", "--yes", "--keyring-backend=test", "--log_format=json", "--home=/home/babylon/babylondata"} txCommand := append(command, allTxArgs...) - return m.ExecCmd(t, m.ContainerName(nodeName), txCommand, successStr) + return m.ExecCmd(t, containerName, txCommand, successStr) } // ExecHermesCmd executes command on the hermes relaer container. @@ -248,14 +248,14 @@ func (m *Manager) RunRlyResource(chainAID, osmoARelayerNodeName, osmoAValMnemoni // RunNodeResource runs a node container. Assings containerName to the container. // Mounts the container on valConfigDir volume on the running host. Returns the container resource and error if any. -func (m *Manager) RunNodeResource(chainId string, nodeName, valCondifDir string) (*dockertest.Resource, error) { +func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir string) (*dockertest.Resource, error) { pwd, err := os.Getwd() if err != nil { return nil, err } runOpts := &dockertest.RunOptions{ - Name: m.ContainerName(nodeName), + Name: containerName, Repository: m.CurrentRepository, NetworkID: m.network.Network.ID, User: "root:root", @@ -277,7 +277,7 @@ func (m *Manager) RunNodeResource(chainId string, nodeName, valCondifDir string) return nil, err } - m.resources[m.ContainerName(nodeName)] = resource + m.resources[containerName] = resource return resource, nil } @@ -288,10 +288,10 @@ func (m *Manager) PurgeResource(resource *dockertest.Resource) error { } // GetNodeResource returns the node resource for containerName. -func (m *Manager) GetNodeResource(nodeName string) (*dockertest.Resource, error) { - resource, exists := m.resources[m.ContainerName(nodeName)] +func (m *Manager) GetNodeResource(containerName string) (*dockertest.Resource, error) { + resource, exists := m.resources[containerName] if !exists { - return nil, fmt.Errorf("node resource not found: container name: %s", nodeName) + return nil, fmt.Errorf("node resource not found: container name: %s", containerName) } return resource, nil } @@ -310,8 +310,8 @@ func (m *Manager) GetHostPort(nodeName string, portId string) (string, error) { // RemoveNodeResource removes a node container specified by containerName. // Returns error if any. -func (m *Manager) RemoveNodeResource(nodeName string) error { - resource, err := m.GetNodeResource(nodeName) +func (m *Manager) RemoveNodeResource(containerName string) error { + resource, err := m.GetNodeResource(containerName) if err != nil { return err } @@ -321,7 +321,7 @@ func (m *Manager) RemoveNodeResource(nodeName string) error { if err := m.pool.Client.RemoveContainer(opts); err != nil { return err } - delete(m.resources, m.ContainerName(nodeName)) + delete(m.resources, containerName) return nil } @@ -403,8 +403,3 @@ func (m *Manager) HermesContainerName() string { func (m *Manager) CosmosRlyrContainerName() string { return fmt.Sprintf("%s-%s", cosmosRelayerContainerName, m.identifier) } - -// ContainerName returns the container name concatenated with the identifier -func (m *Manager) ContainerName(nodeName string) string { - return fmt.Sprintf("%s-%s", nodeName, m.identifier) -} From f34b3d3622216fae2018992dac255577ee2956ef Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 08:50:58 -0300 Subject: [PATCH 76/89] chore: remove unecessary multistage parts --- contrib/images/babylond/Dockerfile | 14 ++++---------- contrib/images/e2e-initialization/init.Dockerfile | 1 - 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/contrib/images/babylond/Dockerfile b/contrib/images/babylond/Dockerfile index 7f121ae18..e8262e215 100644 --- a/contrib/images/babylond/Dockerfile +++ b/contrib/images/babylond/Dockerfile @@ -1,7 +1,10 @@ -FROM golang:1.21 as go-bbn +FROM golang:1.21 as build-env # Version to build. Default is empty ARG VERSION +ARG BUILD_TAGS="" +ARG LEDGER_ENABLED="false" +ARG COSMOS_BUILD_OPTIONS="" WORKDIR /go/src/github.com/babylonlabs-io/babylon COPY ./ /go/src/github.com/babylonlabs-io/babylon/ @@ -12,17 +15,9 @@ RUN if [ -n "${VERSION}" ]; then \ git checkout -f ${VERSION}; \ fi -FROM go-bbn as go-bbn-dep - # Cache mod dependencies RUN go mod download -FROM go-bbn-dep as build-env - -ARG BUILD_TAGS="" -ARG LEDGER_ENABLED="false" -ARG COSMOS_BUILD_OPTIONS="" - RUN LEDGER_ENABLED=$LEDGER_ENABLED \ BUILD_TAGS=$BUILD_TAGS \ COSMOS_BUILD_OPTIONS=$COSMOS_BUILD_OPTIONS \ @@ -41,5 +36,4 @@ LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/babylon RUN wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.x86_64.so \ -O /lib/libwasmvm.x86_64.so -FROM wasm-link as final COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/build/babylond /bin/babylond diff --git a/contrib/images/e2e-initialization/init.Dockerfile b/contrib/images/e2e-initialization/init.Dockerfile index 5026dda51..f176c6dcb 100644 --- a/contrib/images/e2e-initialization/init.Dockerfile +++ b/contrib/images/e2e-initialization/init.Dockerfile @@ -20,7 +20,6 @@ LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/babylon RUN wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.x86_64.so \ -O /lib/libwasmvm.x86_64.so -FROM wasm-link as final # Args only last for a single build stage - renew ARG E2E_SCRIPT_NAME From 8e8db822ff6a5fa75e0f073c3b28484938cdb87e Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 10:02:58 -0300 Subject: [PATCH 77/89] chore: add logs for it --- test/e2e/btc_timestamping_e2e_test.go | 1 - test/e2e/configurer/base.go | 2 ++ test/e2e/configurer/chain/node.go | 1 + test/e2e/configurer/current.go | 5 +++-- test/e2e/configurer/upgrade.go | 2 +- test/e2e/containers/containers.go | 3 +++ test/e2e/initialization/init.go | 2 ++ test/e2e/initialization/node.go | 1 + 8 files changed, 13 insertions(+), 4 deletions(-) diff --git a/test/e2e/btc_timestamping_e2e_test.go b/test/e2e/btc_timestamping_e2e_test.go index 8884209cc..8e985113d 100644 --- a/test/e2e/btc_timestamping_e2e_test.go +++ b/test/e2e/btc_timestamping_e2e_test.go @@ -38,7 +38,6 @@ func (s *BTCTimestampingTestSuite) SetupSuite() { // 3. Run IBC relayer between the two chains. // 4. Execute various e2e tests, including IBC s.configurer, err = configurer.NewBTCTimestampingConfigurer(s.T(), true) - s.Require().NoError(err) err = s.configurer.ConfigureChains() diff --git a/test/e2e/configurer/base.go b/test/e2e/configurer/base.go index de34baa2e..7857397f6 100644 --- a/test/e2e/configurer/base.go +++ b/test/e2e/configurer/base.go @@ -70,6 +70,8 @@ func (bc *baseConfigurer) RunValidators() error { func (bc *baseConfigurer) runValidators(chainConfig *chain.Config) error { bc.t.Logf("starting %s validator containers...", chainConfig.Id) for _, node := range chainConfig.NodeConfigs { + fmt.Printf("\n runValidators: %s - ", node.Name) + if err := node.Run(); err != nil { return err } diff --git a/test/e2e/configurer/chain/node.go b/test/e2e/configurer/chain/node.go index c07288c17..085cbd872 100644 --- a/test/e2e/configurer/chain/node.go +++ b/test/e2e/configurer/chain/node.go @@ -53,6 +53,7 @@ func (n *NodeConfig) Run() error { if err != nil { return err } + fmt.Printf("\n running node resource %s - chainId: %s", n.Name, n.chainId) hostPort := resource.GetHostPort("26657/tcp") rpcClient, err := rpchttp.New("tcp://"+hostPort, "/websocket") diff --git a/test/e2e/configurer/current.go b/test/e2e/configurer/current.go index ca2c26ae6..a6686e13e 100644 --- a/test/e2e/configurer/current.go +++ b/test/e2e/configurer/current.go @@ -1,6 +1,7 @@ package configurer import ( + "fmt" "os" "testing" "time" @@ -40,12 +41,12 @@ func (cb *CurrentBranchConfigurer) ConfigureChains() error { func (cb *CurrentBranchConfigurer) ConfigureChain(chainConfig *chain.Config) error { cb.t.Logf("starting e2e infrastructure from current branch for chain-id: %s", chainConfig.Id) - tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-") + tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-*") if err != nil { return err } cb.t.Logf("temp directory for chain-id %v: %v", chainConfig.Id, tmpDir) - + fmt.Printf("\n tmp dir for config chain %s - ", tmpDir) initializedChain, err := initialization.InitChain( chainConfig.Id, tmpDir, diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index 20f5f8bab..0b40c106d 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -81,7 +81,7 @@ func (uc *UpgradeConfigurer) ConfigureChains() error { func (uc *UpgradeConfigurer) ConfigureChain(chainConfig *chain.Config) error { uc.t.Logf("starting upgrade e2e infrastructure for chain-id: %s", chainConfig.Id) - tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-") + tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-*") if err != nil { return err } diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 143afbb80..c36ba1eba 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -254,6 +254,7 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st return nil, err } + fmt.Printf("\nrunning RunNodeResource container name %s", containerName) runOpts := &dockertest.RunOptions{ Name: containerName, Repository: m.CurrentRepository, @@ -361,6 +362,8 @@ func (m *Manager) RunChainInitResource(chainId string, chainVotingPeriod, chainE votingPeriodDuration := time.Duration(chainVotingPeriod * 1000000000) expeditedVotingPeriodDuration := time.Duration(chainExpeditedVotingPeriod * 1000000000) + fmt.Printf("\n running RunChainInitResource %s", chainId) + fmt.Printf("\n running network %s", m.network.Network.ID) initResource, err := m.pool.RunWithOptions( &dockertest.RunOptions{ Name: chainId, diff --git a/test/e2e/initialization/init.go b/test/e2e/initialization/init.go index 94e8ca3e5..04828a4e5 100644 --- a/test/e2e/initialization/init.go +++ b/test/e2e/initialization/init.go @@ -17,6 +17,7 @@ func InitChain(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod, expe } for _, nodeConfig := range nodeConfigs { + fmt.Printf("\n newNode node %s-%s is Validator %+v", chain.chainMeta.Id, nodeConfig.Name, nodeConfig.IsValidator) newNode, err := newNode(chain, nodeConfig) if err != nil { return nil, err @@ -32,6 +33,7 @@ func InitChain(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod, expe for _, peer := range chain.nodes { peerID := fmt.Sprintf("%s@%s:26656", peer.getNodeKey().ID(), peer.moniker) peer.peerId = peerID + fmt.Printf("\n node peerID: %s - moniker %s", peerID, peer.moniker) peers = append(peers, peerID) } diff --git a/test/e2e/initialization/node.go b/test/e2e/initialization/node.go index 17eddb24d..effefc48e 100644 --- a/test/e2e/initialization/node.go +++ b/test/e2e/initialization/node.go @@ -352,6 +352,7 @@ func (n *internalNode) initNodeConfigs(persistentPeers []string) error { valConfig.P2P.ListenAddress = "tcp://0.0.0.0:26656" valConfig.P2P.AddrBookStrict = false valConfig.P2P.ExternalAddress = fmt.Sprintf("%s:%d", n.moniker, 26656) + fmt.Printf("\ninitNodeConfigs %+v - external addr %s", persistentPeers, valConfig.P2P.ExternalAddress) valConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657" valConfig.StateSync.Enable = false valConfig.LogLevel = "debug" From cc9c7867e6c1a8f30dea93497c4124f78bf463e3 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 11:34:01 -0300 Subject: [PATCH 78/89] chore: cap identifier size --- test/e2e/configurer/base.go | 2 +- test/e2e/configurer/current.go | 3 ++- test/e2e/configurer/factory.go | 13 +++++++++++-- test/e2e/containers/containers.go | 8 +++++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/test/e2e/configurer/base.go b/test/e2e/configurer/base.go index 7857397f6..6b0f79d80 100644 --- a/test/e2e/configurer/base.go +++ b/test/e2e/configurer/base.go @@ -70,7 +70,7 @@ func (bc *baseConfigurer) RunValidators() error { func (bc *baseConfigurer) runValidators(chainConfig *chain.Config) error { bc.t.Logf("starting %s validator containers...", chainConfig.Id) for _, node := range chainConfig.NodeConfigs { - fmt.Printf("\n runValidators: %s - ", node.Name) + fmt.Printf("\n runValidators: %s", node.Name) if err := node.Run(); err != nil { return err diff --git a/test/e2e/configurer/current.go b/test/e2e/configurer/current.go index a6686e13e..5f58b364c 100644 --- a/test/e2e/configurer/current.go +++ b/test/e2e/configurer/current.go @@ -32,6 +32,7 @@ func NewCurrentBranchConfigurer(t *testing.T, chainConfigs []*chain.Config, setu func (cb *CurrentBranchConfigurer) ConfigureChains() error { cb.t.Logf("Current branch configure chains") for _, chainConfig := range cb.chainConfigs { + fmt.Printf("\nconfigure chain :%s - %s", chainConfig.Id, chainConfig.DataDir) if err := cb.ConfigureChain(chainConfig); err != nil { return err } @@ -46,7 +47,7 @@ func (cb *CurrentBranchConfigurer) ConfigureChain(chainConfig *chain.Config) err return err } cb.t.Logf("temp directory for chain-id %v: %v", chainConfig.Id, tmpDir) - fmt.Printf("\n tmp dir for config chain %s - ", tmpDir) + fmt.Printf("\n tmp dir for config chain %s - %+v", tmpDir, chainConfig) initializedChain, err := initialization.InitChain( chainConfig.Id, tmpDir, diff --git a/test/e2e/configurer/factory.go b/test/e2e/configurer/factory.go index 682109b1d..f849b2693 100644 --- a/test/e2e/configurer/factory.go +++ b/test/e2e/configurer/factory.go @@ -1,6 +1,8 @@ package configurer import ( + "crypto/sha256" + "encoding/hex" "fmt" "strings" "testing" @@ -112,6 +114,8 @@ var ( } ) +const MaxIndetifierSize = 10 + // NewBTCTimestampingConfigurer returns a new Configurer for BTC timestamping service. // TODO currently only one configuration is available. Consider testing upgrades // when necessary @@ -213,7 +217,6 @@ func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradeP return NewUpgradeConfigurer(t, []*chain.Config{ - // we only need 1 chain for testing upgrade chain.New(t, containerManager, initialization.ChainAID, updateNodeConfigNameWithIdentifier(validatorConfigsChainA, identifier), nil), }, @@ -226,7 +229,13 @@ func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradeP func identifierName(t *testing.T) string { str := strings.ToLower(t.Name()) - return strings.ReplaceAll(str, "/", "-") + str = strings.ReplaceAll(str, "/", "-") + h := sha256.New() + hex := hex.EncodeToString(h.Sum([]byte(str))) + if len(hex) > MaxIndetifierSize { // cap size to first MaxIndetifierSize + return hex[:MaxIndetifierSize-1] + } + return hex } func updateNodeConfigNameWithIdentifier(cfgs []*initialization.NodeConfig, identifier string) []*initialization.NodeConfig { diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index c36ba1eba..da91763ad 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -57,6 +57,7 @@ func NewManager(identifier string, isDebugLogEnabled bool, isCosmosRelayer, isUp if err != nil { return nil, err } + fmt.Printf("\n\ncreating network %s - %s\n\n", m.NetworkName(), m.network.Network.ID) return m, nil } @@ -258,8 +259,9 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st runOpts := &dockertest.RunOptions{ Name: containerName, Repository: m.CurrentRepository, - NetworkID: m.network.Network.ID, - User: "root:root", + // NetworkID: m.network.Network.ID, + Networks: []*dockertest.Network{m.network}, + User: "root:root", Entrypoint: []string{ "sh", "-c", @@ -272,7 +274,7 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st fmt.Sprintf("%s/upgrades:/upgrades", pwd), }, } - + fmt.Printf("\n\n run opts docker: %+v", runOpts) resource, err := m.pool.RunWithOptions(runOpts, noRestart) if err != nil { return nil, err From 0ccb5f5c6df7a888c2523a6c8c94c092e58b0ce4 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 12:06:08 -0300 Subject: [PATCH 79/89] chore: remove artifact checker --- .github/workflows/ci.yml | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ecd31611f..135ede4ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,47 +108,43 @@ jobs: e2e-docker-build-babylon-before-upgrade: runs-on: ubuntu-22.04 steps: - - name: Artifact babylond-before-upgrade exists # TODO: check why it doesn't work to load from older workflow runs .-. - uses: xSAVIKx/artifact-exists-action@v0 - id: check-babylond-before-upgrade - with: - name: babylond-before-upgrade + # - name: Artifact babylond-before-upgrade exists # TODO: check why it doesn't work to load from older workflow runs .-. + # uses: xSAVIKx/artifact-exists-action@v0 + # id: check-babylond-before-upgrade + # with: + # name: babylond-before-upgrade - name: Checkout repository uses: actions/checkout@v4 - - name: Build docker and save babylond-before-upgrade - if: steps.check-babylond-before-upgrade.outputs.exists == 'false' + - name: Build docker babylond-before-upgrade run: | make -C contrib/images babylond-before-upgrade + - name: Docker save babylond-before-upgrade + run: | docker save -o /tmp/docker-babylond-before-upgrade.tar.gz babylonlabs-io/babylond-before-upgrade:latest - name: Upload babylond-before-upgrade artifact uses: actions/upload-artifact@v4 with: name: babylond-before-upgrade path: /tmp/docker-babylond-before-upgrade.tar.gz - retention-days: 90 + # retention-days: 90 e2e-docker-build-e2e-init-chain: runs-on: ubuntu-22.04 steps: - - name: Artifact init-chain exists - uses: xSAVIKx/artifact-exists-action@v0 - id: check-init-chain - with: - name: init-chain - - name: Checkout repository uses: actions/checkout@v4 - - name: Build docker and save init-chain - if: steps.check-init-chain.outputs.exists == 'false' + - name: Build docker init-chain run: | make -C contrib/images e2e-init-chain + - name: Docker save init-chain + run: | docker save -o /tmp/docker-init-chain.tar.gz babylonlabs-io/babylond-e2e-init-chain:latest - name: Upload init-chain artifact uses: actions/upload-artifact@v4 with: name: init-chain path: /tmp/docker-init-chain.tar.gz - retention-days: 90 + # retention-days: 90 e2e-run-ibc-transfer: needs: [e2e-docker-build-babylon, build] From 7ff9ab31c4bf0349848317548343371cd79118aa Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 12:53:04 -0300 Subject: [PATCH 80/89] chore: add logs to debug e2e upgrade --- test/e2e/configurer/chain/node.go | 3 +++ test/e2e/configurer/upgrade.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test/e2e/configurer/chain/node.go b/test/e2e/configurer/chain/node.go index 085cbd872..ff00541c1 100644 --- a/test/e2e/configurer/chain/node.go +++ b/test/e2e/configurer/chain/node.go @@ -49,6 +49,7 @@ func NewNodeConfig(t *testing.T, initNode *initialization.Node, initConfig *init // method. func (n *NodeConfig) Run() error { n.t.Logf("starting node container: %s", n.Name) + fmt.Printf("Start Run node %+v", n) resource, err := n.containerManager.RunNodeResource(n.chainId, n.Name, n.ConfigDir) if err != nil { return err @@ -66,9 +67,11 @@ func (n *NodeConfig) Run() error { require.Eventually( n.t, func() bool { + fmt.Printf("eventually check query current height %+v", n) // This fails if unsuccessful. _, err := n.QueryCurrentHeight() if err != nil { + fmt.Printf("err on QueryCurrentHeight %s", err.Error()) return false } n.t.Logf("started node container: %s", n.Name) diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index 0b40c106d..eda736b58 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -180,6 +180,7 @@ func (uc *UpgradeConfigurer) RunUpgrade() error { } func (uc *UpgradeConfigurer) runProposalUpgrade() error { + fmt.Printf("running runProposalUpgrade for %+v", uc.chainConfigs) // submit, deposit, and vote for upgrade proposal // prop height = current height + voting period + time it takes to submit proposal + small buffer for _, chainConfig := range uc.chainConfigs { @@ -203,7 +204,7 @@ func (uc *UpgradeConfigurer) runProposalUpgrade() error { for _, chainConfig := range uc.chainConfigs { uc.t.Logf("waiting to reach upgrade height on chain %s", chainConfig.Id) chainConfig.WaitUntilHeight(chainConfig.UpgradePropHeight) - uc.t.Logf("upgrade height reached on chain %s", chainConfig.Id) + uc.t.Logf("upgrade height %d reached on chain %s", chainConfig.UpgradePropHeight, chainConfig.Id) } // remove all containers so we can upgrade them to the new version @@ -218,6 +219,7 @@ func (uc *UpgradeConfigurer) runProposalUpgrade() error { // remove all containers so we can upgrade them to the new version for _, chainConfig := range uc.chainConfigs { + fmt.Printf("\n upgradeContainers %+v - prop height %d", chainConfig, chainConfig.UpgradePropHeight) if err := uc.upgradeContainers(chainConfig, chainConfig.UpgradePropHeight); err != nil { return err } @@ -258,6 +260,7 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe // Check if any of the goroutines returned an error for err := range errCh { if err != nil { + fmt.Printf("err on running node %s", err.Error()) return err } } From 9afdd95262d2ff3f07dd59ca3132239b77bee8d4 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 14:38:04 -0300 Subject: [PATCH 81/89] fix: use babylond with e2e tag for all e2e testing --- .github/workflows/ci.yml | 7 +++++-- test/e2e/configurer/chain/node.go | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 135ede4ef..5620ad331 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,7 +95,7 @@ jobs: uses: actions/checkout@v4 - name: Build docker babylond run: | - make -C contrib/images babylond + make -C contrib/images babylond-e2e - name: Docker save babylon run: | docker save -o /tmp/docker-babylond.tar.gz babylonlabs-io/babylond:latest @@ -295,16 +295,19 @@ jobs: - 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 TestSoftwareUpgradeTestSuite run: | - make test-e2e-cache-upgrade-vanilla \ No newline at end of file + sudo make test-e2e-cache-upgrade-vanilla \ No newline at end of file diff --git a/test/e2e/configurer/chain/node.go b/test/e2e/configurer/chain/node.go index ff00541c1..25080cbd3 100644 --- a/test/e2e/configurer/chain/node.go +++ b/test/e2e/configurer/chain/node.go @@ -67,7 +67,7 @@ func (n *NodeConfig) Run() error { require.Eventually( n.t, func() bool { - fmt.Printf("eventually check query current height %+v", n) + fmt.Printf("\neventually check query current height %+v", n) // This fails if unsuccessful. _, err := n.QueryCurrentHeight() if err != nil { From e104607a6bf769758566bb6fe71565f0a4ef2dd9 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 15:05:40 -0300 Subject: [PATCH 82/89] chore: add ci template back for all cases except e2e test --- .github/workflows/ci.yml | 100 ++++++++------------------------------- 1 file changed, 21 insertions(+), 79 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5620ad331..f409db80a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,79 +10,21 @@ concurrency: cancel-in-progress: true jobs: - build: - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.21 - - - name: Print Go environment - run: go env - - - name: Build Application - run: make build - -# needs: build, in other jobs is to utilize the go cache created by build - lint: - needs: build - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.21 - - - name: Run Lint - uses: golangci/golangci-lint-action@v6 - with: - version: v1.59 - args: --timeout=10m - - unit-tests: - needs: build - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.21 - - - name: Run Unit Tests - run: | - make test - - check-mock-gen: - needs: build - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.21 - - - name: Run make mock-gen - run: make mocks - - - name: Check for uncommitted changes - run: | - if ! git diff --exit-code; then - echo "Uncommitted changes detected. Please run 'make mocks' before committing." - exit 1 - fi + lint_test: + uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.2.1 + secrets: inherit + with: + run-unit-tests: true + run-integration-tests: false + run-lint: true + + docker_pipeline: + uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.2.1 + secrets: inherit + with: + publish: false + dockerfile: ./contrib/images/babylond/Dockerfile + repoName: babylond ############################################################################### ### E2E ### @@ -147,7 +89,7 @@ jobs: # retention-days: 90 e2e-run-ibc-transfer: - needs: [e2e-docker-build-babylon, build] + needs: [e2e-docker-build-babylon] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -174,7 +116,7 @@ jobs: make test-e2e-cache-ibc-transfer e2e-run-btc-timestamping: - needs: [e2e-docker-build-babylon, build] + needs: [e2e-docker-build-babylon] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -196,7 +138,7 @@ jobs: make test-e2e-cache-btc-timestamping e2e-run-btc-timestamping-phase-2-hermes: - needs: [e2e-docker-build-babylon, build] + needs: [e2e-docker-build-babylon] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -223,7 +165,7 @@ jobs: make test-e2e-cache-btc-timestamping-phase-2-hermes e2e-run-btc-timestamping-phase-2-rly: - needs: [e2e-docker-build-babylon, build] + needs: [e2e-docker-build-babylon] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -250,7 +192,7 @@ jobs: make test-e2e-cache-btc-timestamping-phase-2-rly e2e-run-btc-staking: - needs: [e2e-docker-build-babylon, build] + needs: [e2e-docker-build-babylon] runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -272,7 +214,7 @@ jobs: make test-e2e-cache-btc-staking e2e-run-upgrade-vanilla: - needs: [e2e-docker-build-babylon, e2e-docker-build-babylon-before-upgrade, e2e-docker-build-e2e-init-chain, build] + 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 From 2f7e46c70ab8ebb9cc2c600536e70bf553593b65 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 15:12:11 -0300 Subject: [PATCH 83/89] chore: remove debug comments and rollback to use network id --- .github/workflows/ci.yml | 2 +- test/e2e/configurer/base.go | 2 -- test/e2e/configurer/chain/node.go | 4 ---- test/e2e/configurer/current.go | 3 --- test/e2e/configurer/upgrade.go | 1 - test/e2e/containers/containers.go | 9 +++------ test/e2e/initialization/init.go | 2 -- test/e2e/initialization/node.go | 1 - 8 files changed, 4 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f409db80a..b3c378f44 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,7 +68,7 @@ jobs: with: name: babylond-before-upgrade path: /tmp/docker-babylond-before-upgrade.tar.gz - # retention-days: 90 + # retention-days: 90 active this back if artifact-exists-action works e2e-docker-build-e2e-init-chain: runs-on: ubuntu-22.04 diff --git a/test/e2e/configurer/base.go b/test/e2e/configurer/base.go index 6b0f79d80..de34baa2e 100644 --- a/test/e2e/configurer/base.go +++ b/test/e2e/configurer/base.go @@ -70,8 +70,6 @@ func (bc *baseConfigurer) RunValidators() error { func (bc *baseConfigurer) runValidators(chainConfig *chain.Config) error { bc.t.Logf("starting %s validator containers...", chainConfig.Id) for _, node := range chainConfig.NodeConfigs { - fmt.Printf("\n runValidators: %s", node.Name) - if err := node.Run(); err != nil { return err } diff --git a/test/e2e/configurer/chain/node.go b/test/e2e/configurer/chain/node.go index 25080cbd3..c07288c17 100644 --- a/test/e2e/configurer/chain/node.go +++ b/test/e2e/configurer/chain/node.go @@ -49,12 +49,10 @@ func NewNodeConfig(t *testing.T, initNode *initialization.Node, initConfig *init // method. func (n *NodeConfig) Run() error { n.t.Logf("starting node container: %s", n.Name) - fmt.Printf("Start Run node %+v", n) resource, err := n.containerManager.RunNodeResource(n.chainId, n.Name, n.ConfigDir) if err != nil { return err } - fmt.Printf("\n running node resource %s - chainId: %s", n.Name, n.chainId) hostPort := resource.GetHostPort("26657/tcp") rpcClient, err := rpchttp.New("tcp://"+hostPort, "/websocket") @@ -67,11 +65,9 @@ func (n *NodeConfig) Run() error { require.Eventually( n.t, func() bool { - fmt.Printf("\neventually check query current height %+v", n) // This fails if unsuccessful. _, err := n.QueryCurrentHeight() if err != nil { - fmt.Printf("err on QueryCurrentHeight %s", err.Error()) return false } n.t.Logf("started node container: %s", n.Name) diff --git a/test/e2e/configurer/current.go b/test/e2e/configurer/current.go index 5f58b364c..2bb4c9081 100644 --- a/test/e2e/configurer/current.go +++ b/test/e2e/configurer/current.go @@ -1,7 +1,6 @@ package configurer import ( - "fmt" "os" "testing" "time" @@ -32,7 +31,6 @@ func NewCurrentBranchConfigurer(t *testing.T, chainConfigs []*chain.Config, setu func (cb *CurrentBranchConfigurer) ConfigureChains() error { cb.t.Logf("Current branch configure chains") for _, chainConfig := range cb.chainConfigs { - fmt.Printf("\nconfigure chain :%s - %s", chainConfig.Id, chainConfig.DataDir) if err := cb.ConfigureChain(chainConfig); err != nil { return err } @@ -47,7 +45,6 @@ func (cb *CurrentBranchConfigurer) ConfigureChain(chainConfig *chain.Config) err return err } cb.t.Logf("temp directory for chain-id %v: %v", chainConfig.Id, tmpDir) - fmt.Printf("\n tmp dir for config chain %s - %+v", tmpDir, chainConfig) initializedChain, err := initialization.InitChain( chainConfig.Id, tmpDir, diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index eda736b58..54e311028 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -219,7 +219,6 @@ func (uc *UpgradeConfigurer) runProposalUpgrade() error { // remove all containers so we can upgrade them to the new version for _, chainConfig := range uc.chainConfigs { - fmt.Printf("\n upgradeContainers %+v - prop height %d", chainConfig, chainConfig.UpgradePropHeight) if err := uc.upgradeContainers(chainConfig, chainConfig.UpgradePropHeight); err != nil { return err } diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index da91763ad..32e82d0e8 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -259,9 +259,8 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st runOpts := &dockertest.RunOptions{ Name: containerName, Repository: m.CurrentRepository, - // NetworkID: m.network.Network.ID, - Networks: []*dockertest.Network{m.network}, - User: "root:root", + NetworkID: m.network.Network.ID, + User: "root:root", Entrypoint: []string{ "sh", "-c", @@ -274,7 +273,7 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st fmt.Sprintf("%s/upgrades:/upgrades", pwd), }, } - fmt.Printf("\n\n run opts docker: %+v", runOpts) + resource, err := m.pool.RunWithOptions(runOpts, noRestart) if err != nil { return nil, err @@ -364,8 +363,6 @@ func (m *Manager) RunChainInitResource(chainId string, chainVotingPeriod, chainE votingPeriodDuration := time.Duration(chainVotingPeriod * 1000000000) expeditedVotingPeriodDuration := time.Duration(chainExpeditedVotingPeriod * 1000000000) - fmt.Printf("\n running RunChainInitResource %s", chainId) - fmt.Printf("\n running network %s", m.network.Network.ID) initResource, err := m.pool.RunWithOptions( &dockertest.RunOptions{ Name: chainId, diff --git a/test/e2e/initialization/init.go b/test/e2e/initialization/init.go index 04828a4e5..94e8ca3e5 100644 --- a/test/e2e/initialization/init.go +++ b/test/e2e/initialization/init.go @@ -17,7 +17,6 @@ func InitChain(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod, expe } for _, nodeConfig := range nodeConfigs { - fmt.Printf("\n newNode node %s-%s is Validator %+v", chain.chainMeta.Id, nodeConfig.Name, nodeConfig.IsValidator) newNode, err := newNode(chain, nodeConfig) if err != nil { return nil, err @@ -33,7 +32,6 @@ func InitChain(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod, expe for _, peer := range chain.nodes { peerID := fmt.Sprintf("%s@%s:26656", peer.getNodeKey().ID(), peer.moniker) peer.peerId = peerID - fmt.Printf("\n node peerID: %s - moniker %s", peerID, peer.moniker) peers = append(peers, peerID) } diff --git a/test/e2e/initialization/node.go b/test/e2e/initialization/node.go index effefc48e..17eddb24d 100644 --- a/test/e2e/initialization/node.go +++ b/test/e2e/initialization/node.go @@ -352,7 +352,6 @@ func (n *internalNode) initNodeConfigs(persistentPeers []string) error { valConfig.P2P.ListenAddress = "tcp://0.0.0.0:26656" valConfig.P2P.AddrBookStrict = false valConfig.P2P.ExternalAddress = fmt.Sprintf("%s:%d", n.moniker, 26656) - fmt.Printf("\ninitNodeConfigs %+v - external addr %s", persistentPeers, valConfig.P2P.ExternalAddress) valConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657" valConfig.StateSync.Enable = false valConfig.LogLevel = "debug" From 7b850aa9a5ae1bacd5c116a3cf6e082040aa4874 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 15:19:09 -0300 Subject: [PATCH 84/89] chore: update directive of dockerfile --- contrib/images/babylond/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/images/babylond/Dockerfile b/contrib/images/babylond/Dockerfile index e8262e215..9b6687732 100644 --- a/contrib/images/babylond/Dockerfile +++ b/contrib/images/babylond/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21 as build-env +FROM golang:1.21 AS build-env # Version to build. Default is empty ARG VERSION From a2a76fe60ed0ada284c6ae71c8ddcf1bf30fadfc Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 15:36:00 -0300 Subject: [PATCH 85/89] chore: remove debug logs --- test/e2e/configurer/upgrade.go | 2 -- test/e2e/containers/containers.go | 2 -- 2 files changed, 4 deletions(-) diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index 54e311028..60ea7ded0 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -180,7 +180,6 @@ func (uc *UpgradeConfigurer) RunUpgrade() error { } func (uc *UpgradeConfigurer) runProposalUpgrade() error { - fmt.Printf("running runProposalUpgrade for %+v", uc.chainConfigs) // submit, deposit, and vote for upgrade proposal // prop height = current height + voting period + time it takes to submit proposal + small buffer for _, chainConfig := range uc.chainConfigs { @@ -259,7 +258,6 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe // Check if any of the goroutines returned an error for err := range errCh { if err != nil { - fmt.Printf("err on running node %s", err.Error()) return err } } diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 32e82d0e8..143afbb80 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -57,7 +57,6 @@ func NewManager(identifier string, isDebugLogEnabled bool, isCosmosRelayer, isUp if err != nil { return nil, err } - fmt.Printf("\n\ncreating network %s - %s\n\n", m.NetworkName(), m.network.Network.ID) return m, nil } @@ -255,7 +254,6 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st return nil, err } - fmt.Printf("\nrunning RunNodeResource container name %s", containerName) runOpts := &dockertest.RunOptions{ Name: containerName, Repository: m.CurrentRepository, From e6cbb29170cde95d946445ae746211c05de838e1 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Thu, 8 Aug 2024 15:37:33 -0300 Subject: [PATCH 86/89] chore: add run of signet test --- .github/workflows/ci.yml | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26ec8150d..b301b791a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -253,3 +253,44 @@ jobs: - name: Run e2e TestSoftwareUpgradeTestSuite run: | 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 From 29879075c8fdd63e6932a4215422a0ca542db6f5 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 9 Aug 2024 08:56:45 -0300 Subject: [PATCH 87/89] chore: removed e2e test run on publish ci --- .github/workflows/publish.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b5c3cdb81..e1081410b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,10 +13,8 @@ jobs: uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 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/reusable_docker_pipeline.yml@v0.1.0 From 6a4027db37a9c53969d74f91a94d47b37829fbe6 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 9 Aug 2024 10:41:07 -0300 Subject: [PATCH 88/89] chore: rename headerZero to headerGenesis --- app/test_helpers.go | 14 +++++++------- app/upgrades/signetlaunch/upgrades_test.go | 4 ++-- .../e2e/software_upgrade_e2e_signet_launch_test.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/test_helpers.go b/app/test_helpers.go index fd3ac6f6d..5a6d9cbd7 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -358,21 +358,21 @@ func initAccountWithCoins(app *BabylonApp, ctx sdk.Context, addr sdk.AccAddress, } } -// SignetBtcHeaderZero returns the BTC Header block zero from signet. -func SignetBtcHeaderZero(cdc codec.Codec) (*btclighttypes.BTCHeaderInfo, error) { - var btcHeaderZero btclighttypes.BTCHeaderInfo +// 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 - btcHeaderZeroStr := `{ + btcHeaderGenesisStr := `{ "header": "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a008f4d5fae77031e8ad22203", "hash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6", "work": "77414720" }` - buff := bytes.NewBufferString(btcHeaderZeroStr) + buff := bytes.NewBufferString(btcHeaderGenesisStr) - err := cdc.UnmarshalJSON(buff.Bytes(), &btcHeaderZero) + err := cdc.UnmarshalJSON(buff.Bytes(), &btcHeaderGenesis) if err != nil { return nil, err } - return &btcHeaderZero, nil + return &btcHeaderGenesis, nil } diff --git a/app/upgrades/signetlaunch/upgrades_test.go b/app/upgrades/signetlaunch/upgrades_test.go index dca7bf44b..caf1409a1 100644 --- a/app/upgrades/signetlaunch/upgrades_test.go +++ b/app/upgrades/signetlaunch/upgrades_test.go @@ -39,13 +39,13 @@ func (s *UpgradeTestSuite) SetupTest() { s.ctx = s.app.BaseApp.NewContextLegacy(false, tmproto.Header{Height: 1, ChainID: "babylon-1", Time: time.Now().UTC()}) s.preModule = upgrade.NewAppModule(s.app.UpgradeKeeper, s.app.AccountKeeper.AddressCodec()) - btcHeaderZero, err := app.SignetBtcHeaderZero(s.app.EncodingConfig().Codec) + btcHeaderGenesis, err := app.SignetBtcHeaderGenesis(s.app.EncodingConfig().Codec) s.NoError(err) k := s.app.BTCLightClientKeeper btclightclient.InitGenesis(s.ctx, s.app.BTCLightClientKeeper, btclighttypes.GenesisState{ Params: k.GetParams(s.ctx), - BtcHeaders: []*btclighttypes.BTCHeaderInfo{btcHeaderZero}, + BtcHeaders: []*btclighttypes.BTCHeaderInfo{btcHeaderGenesis}, }) } diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go index 846f4ca6f..96c85980c 100644 --- a/test/e2e/software_upgrade_e2e_signet_launch_test.go +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -21,9 +21,9 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) SetupSuite() { s.T().Log("setting up e2e integration test suite...") var err error - btcHeaderZero, err := app.SignetBtcHeaderZero(app.NewTmpBabylonApp().AppCodec()) + btcHeaderGenesis, err := app.SignetBtcHeaderGenesis(app.NewTmpBabylonApp().AppCodec()) s.NoError(err) - s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.UpgradeSignetLaunchFilePath, []*btclighttypes.BTCHeaderInfo{btcHeaderZero}) + s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.UpgradeSignetLaunchFilePath, []*btclighttypes.BTCHeaderInfo{btcHeaderGenesis}) s.NoError(err) err = s.configurer.ConfigureChains() s.NoError(err) From 628c1a6693e8c2cc5093d8205182b89c17ad25d2 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 9 Aug 2024 10:54:05 -0300 Subject: [PATCH 89/89] chore: fix concurrent map write --- test/e2e/configurer/upgrade.go | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index a8839a977..1218f242b 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -241,26 +241,8 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe uc.t.Logf("starting upgrade for chain-id: %s...", chainConfig.Id) uc.containerManager.CurrentRepository = containers.BabylonContainerName - errCh := make(chan error, len(chainConfig.NodeConfigs)) - var wg sync.WaitGroup - for _, node := range chainConfig.NodeConfigs { - wg.Add(1) - go func(node *chain.NodeConfig) { - defer wg.Done() - if err := node.Run(); err != nil { - errCh <- err - } - }(node) - } - - // Wait for all goroutines to complete - wg.Wait() - close(errCh) - - // Check if any of the goroutines returned an error - for err := range errCh { - if err != nil { + if err := node.Run(); err != nil { return err } }