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 signet and testnet4 to avoid wrong height #3224

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 9 additions & 1 deletion zetaclient/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"sync"

"github.com/showa-93/go-mask"

"github.com/zeta-chain/node/pkg/chains"
)

// KeyringBackend is the type of keyring backend to use for the hotkey
Expand Down Expand Up @@ -139,7 +141,13 @@
// this will allow new 'zetaclientd' binary to work with old config file
btcCfg, found := c.BTCChainConfigs[chainID]
if !found || btcCfg.Empty() {
btcCfg = c.BitcoinConfig
// fallback to old 'BitcoinConfig' ONLY for mainnet and testnet.
// we don't want observers who hasn't setup their Signet/Testnet4 endpoints to use old config
// because old config is either testnet3 or mainnet which is the incorrect endpoint to use.
if chainID == chains.BitcoinMainnet.ChainId ||
chainID == chains.BitcoinTestnet.ChainId {
btcCfg = c.BitcoinConfig
}

Check warning on line 150 in zetaclient/config/types.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/config/types.go#L149-L150

Added lines #L149 - L150 were not covered by tests
}

return btcCfg, !btcCfg.Empty()
Expand Down
18 changes: 18 additions & 0 deletions zetaclient/config/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ func Test_GetBTCConfig(t *testing.T) {
},
want: false,
},
{
name: "should not fallback to old config if Signet config is not set in the new config",
chainID: chains.BitcoinSignetTestnet.ChainId,
oldCfg: config.BTCConfig{
RPCHost: "localhost",
},
btcCfg: nil, // new config is not set
want: false,
},
{
name: "should not fallback to old config if Testnet4 config is not set in the new config",
chainID: chains.BitcoinTestnet4.ChainId,
oldCfg: config.BTCConfig{
RPCHost: "localhost",
},
btcCfg: nil, // new config is not set
want: false,
},
}

for _, tt := range tests {
Expand Down
21 changes: 16 additions & 5 deletions zetaclient/orchestrator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"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 +33,6 @@
"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 +360,7 @@
continue
}

database, err := db.NewFromSqlite(dbpath, btcDatabaseFilename, true)
database, err := db.NewFromSqlite(dbpath, btcDatabaseFileName(*rawChain), true)
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 +478,20 @@
return added, removed, nil
}

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

// For additional bitcoin networks, we can use the chain name as the database file name
switch chain.ChainId {
case chains.BitcoinMainnet.ChainId, chains.BitcoinTestnet.ChainId:
return btcDatabaseFilename
default:
return chain.Name

Check warning on line 491 in zetaclient/orchestrator/bootstrap.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/orchestrator/bootstrap.go#L490-L491

Added lines #L490 - L491 were not covered by tests
}
}

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