Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use different database file names for btc signet and testnet4 #3225

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

* [3206](https://github.com/zeta-chain/node/pull/3206) - skip Solana unsupported transaction version to not block inbound observation
* [3184](https://github.com/zeta-chain/node/pull/3184) - zetaclient should not retry if inbound vote message validation fails
* [3225](https://github.com/zeta-chain/node/pull/3225) - use separate database file names for btc signet and testnet4

## v23.0.0

Expand Down
40 changes: 40 additions & 0 deletions zetaclient/orchestrator/bootstap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,46 @@ func TestCreateChainObserverMap(t *testing.T) {
})
}

func TestBtcDatabaseFileName(t *testing.T) {
tests := []struct {
name string
chain chains.Chain
expected string
}{
{
name: "should use legacy file name for bitcoin mainnet",
chain: chains.BitcoinMainnet,
expected: "btc_chain_client",
},
{
name: "should use legacy file name for bitcoin testnet3",
chain: chains.BitcoinTestnet,
expected: "btc_chain_client",
},
{
name: "should use new file name for bitcoin regtest",
chain: chains.BitcoinRegtest,
expected: "btc_chain_client_btc_regtest",
},
{
name: "should use new file name for bitcoin signet",
chain: chains.BitcoinSignetTestnet,
expected: "btc_chain_client_btc_signet_testnet",
},
{
name: "should use new file name for bitcoin testnet4",
chain: chains.BitcoinTestnet4,
expected: "btc_chain_client_btc_testnet4",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, btcDatabaseFileName(tt.chain))
})
}
}

func chainParams(supportedChains []chains.Chain) ([]chains.Chain, map[int64]*observertypes.ChainParams) {
params := make(map[int64]*observertypes.ChainParams)

Expand Down
22 changes: 17 additions & 5 deletions zetaclient/orchestrator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package orchestrator

import (
"context"
"fmt"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -11,6 +12,7 @@ import (
"github.com/pkg/errors"
"github.com/tonkeeper/tongo/ton"

"github.com/zeta-chain/node/pkg/chains"
toncontracts "github.com/zeta-chain/node/pkg/contracts/ton"
"github.com/zeta-chain/node/zetaclient/chains/base"
btcobserver "github.com/zeta-chain/node/zetaclient/chains/bitcoin/observer"
Expand All @@ -32,10 +34,6 @@ import (
"github.com/zeta-chain/node/zetaclient/metrics"
)

// btcDatabaseFilename is the Bitcoin database file name now used in mainnet,
// so we keep using it here for backward compatibility
const btcDatabaseFilename = "btc_chain_client"

// CreateSignerMap creates a map of interfaces.ChainSigner (by chainID) for all chains in the config.
// Note that signer construction failure for a chain does not prevent the creation of signers for other chains.
func CreateSignerMap(
Expand Down Expand Up @@ -363,7 +361,7 @@ func syncObserverMap(
continue
}

database, err := db.NewFromSqlite(dbpath, btcDatabaseFilename, true)
database, err := db.NewFromSqlite(dbpath, btcDatabaseFileName(*rawChain), true)
ws4charlie marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
logger.Std.Error().Err(err).Msgf("unable to open database for BTC chain %d", chainID)
continue
Expand Down Expand Up @@ -481,6 +479,20 @@ func syncObserverMap(
return added, removed, nil
}

func btcDatabaseFileName(chain chains.Chain) string {
ws4charlie marked this conversation as resolved.
Show resolved Hide resolved
// legacyBTCDatabaseFilename is the Bitcoin database file name now used in mainnet and testnet3
// so we keep using it here for backward compatibility
const legacyBTCDatabaseFilename = "btc_chain_client"

// For additional bitcoin networks, we use the chain name as the database file name
switch chain.ChainId {
case chains.BitcoinMainnet.ChainId, chains.BitcoinTestnet.ChainId:
ws4charlie marked this conversation as resolved.
Show resolved Hide resolved
return legacyBTCDatabaseFilename
default:
return fmt.Sprintf("%s_%s", legacyBTCDatabaseFilename, chain.Name)
}
}

func makeTONClient(
ctx context.Context,
cfg config.TONConfig,
Expand Down
Loading