Skip to content

Commit 62ec009

Browse files
ws4charlielumtis
andauthored
refactor: simply the IsSendOutTxProcessed func (#1989)
* initial commit to simply IsSendOutTxProcessed func * simplified IsSendOutTxProcessed() method and added unit tests * fix unit test * converted archived cctxs JSON files to GoLang variables; resolved a few PR comments * fixed CI unit test failure * added comment for the return values of function ParseAndCheckZetaEvent --------- Co-authored-by: Lucas Bertrand <[email protected]>
1 parent 58a1b23 commit 62ec009

File tree

49 files changed

+1791
-791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1791
-791
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* [1936](https://github.com/zeta-chain/node/pull/1936) - refactor common package into subpackages and rename to pkg
3030
* [1966](https://github.com/zeta-chain/node/pull/1966) - move TSS vote message from crosschain to observer
3131
* [1853](https://github.com/zeta-chain/node/pull/1853) - refactor vote inbound tx and vote outbound tx
32+
* [1989](https://github.com/zeta-chain/node/pull/1989) - simplify `IsSendOutTxProcessed` method and add unit tests
3233
* [2013](https://github.com/zeta-chain/node/pull/2013) - rename `GasPriceVoter` message to `VoteGasPrice`
3334

3435
### Features

cmd/zetaclientd/debug.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func DebugCmd() *cobra.Command {
100100
ob := evm.ChainClient{
101101
Mu: &sync.Mutex{},
102102
}
103-
ob.WithZetaClient(bridge)
103+
ob.WithZetaBridge(bridge)
104104
ob.WithLogger(chainLogger)
105105
var ethRPC *ethrpc.EthRPC
106106
var client *ethclient.Client

cmd/zetaclientd/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func start(_ *cobra.Command, _ []string) error {
124124

125125
// Initialize core parameters from zetacore
126126
appContext := appcontext.NewAppContext(corecontext.NewZetaCoreContext(cfg), cfg)
127-
err = zetaBridge.UpdateZetaCoreContext(appContext.ZetaCoreContext(), true)
127+
err = zetaBridge.UpdateZetaCoreContext(appContext.ZetaCoreContext(), true, startLogger)
128128
if err != nil {
129129
startLogger.Error().Err(err).Msg("Error getting core parameters")
130130
return err

zetaclient/bitcoin/bitcoin_client.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,15 @@ func (ob *BTCChainClient) ConfirmationsThreshold(amount *big.Int) int64 {
504504
return int64(ob.GetChainParams().ConfirmationCount)
505505
}
506506

507-
// IsSendOutTxProcessed returns isIncluded(or inMempool), isConfirmed, Error
508-
func (ob *BTCChainClient) IsSendOutTxProcessed(cctx *types.CrossChainTx, logger zerolog.Logger) (bool, bool, error) {
507+
// IsOutboundProcessed returns isIncluded(or inMempool), isConfirmed, Error
508+
func (ob *BTCChainClient) IsOutboundProcessed(cctx *types.CrossChainTx, logger zerolog.Logger) (bool, bool, error) {
509509
params := *cctx.GetCurrentOutTxParam()
510510
sendHash := cctx.Index
511511
nonce := cctx.GetCurrentOutTxParam().OutboundTxTssNonce
512512

513513
// get broadcasted outtx and tx result
514514
outTxID := ob.GetTxID(nonce)
515-
logger.Info().Msgf("IsSendOutTxProcessed %s", outTxID)
515+
logger.Info().Msgf("IsOutboundProcessed %s", outTxID)
516516

517517
ob.Mu.Lock()
518518
txnHash, broadcasted := ob.broadcastedTx[outTxID]
@@ -537,7 +537,7 @@ func (ob *BTCChainClient) IsSendOutTxProcessed(cctx *types.CrossChainTx, logger
537537
if txResult == nil { // check failed, try again next time
538538
return false, false, nil
539539
} else if inMempool { // still in mempool (should avoid unnecessary Tss keysign)
540-
ob.logger.OutTx.Info().Msgf("IsSendOutTxProcessed: outTx %s is still in mempool", outTxID)
540+
ob.logger.OutTx.Info().Msgf("IsOutboundProcessed: outTx %s is still in mempool", outTxID)
541541
return true, false, nil
542542
}
543543
// included
@@ -548,7 +548,7 @@ func (ob *BTCChainClient) IsSendOutTxProcessed(cctx *types.CrossChainTx, logger
548548
if res == nil {
549549
return false, false, nil
550550
}
551-
ob.logger.OutTx.Info().Msgf("IsSendOutTxProcessed: setIncludedTx succeeded for outTx %s", outTxID)
551+
ob.logger.OutTx.Info().Msgf("IsOutboundProcessed: setIncludedTx succeeded for outTx %s", outTxID)
552552
}
553553

554554
// It's safe to use cctx's amount to post confirmation because it has already been verified in observeOutTx()
@@ -573,9 +573,9 @@ func (ob *BTCChainClient) IsSendOutTxProcessed(cctx *types.CrossChainTx, logger
573573
coin.CoinType_Gas,
574574
)
575575
if err != nil {
576-
logger.Error().Err(err).Msgf("IsSendOutTxProcessed: error confirming bitcoin outTx %s, nonce %d ballot %s", res.TxID, nonce, ballot)
576+
logger.Error().Err(err).Msgf("IsOutboundProcessed: error confirming bitcoin outTx %s, nonce %d ballot %s", res.TxID, nonce, ballot)
577577
} else if zetaHash != "" {
578-
logger.Info().Msgf("IsSendOutTxProcessed: confirmed Bitcoin outTx %s, zeta tx hash %s nonce %d ballot %s", res.TxID, zetaHash, nonce, ballot)
578+
logger.Info().Msgf("IsOutboundProcessed: confirmed Bitcoin outTx %s, zeta tx hash %s nonce %d ballot %s", res.TxID, zetaHash, nonce, ballot)
579579
}
580580
return true, true, nil
581581
}
+8-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package compliance
22

33
import (
4-
"path"
54
"testing"
65

76
ethcommon "github.com/ethereum/go-ethereum/common"
87
"github.com/stretchr/testify/require"
9-
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
8+
"github.com/zeta-chain/zetacore/pkg/chains"
109
"github.com/zeta-chain/zetacore/zetaclient/config"
1110
"github.com/zeta-chain/zetacore/zetaclient/testutils"
1211
)
1312

1413
func TestCctxRestricted(t *testing.T) {
1514
// load archived cctx
16-
var cctx crosschaintypes.CrossChainTx
17-
testutils.LoadObjectFromJSONFile(t, &cctx, path.Join("../", testutils.TestDataPathCctx, "cctx_1_6270.json"))
15+
chain := chains.EthChain()
16+
cctx := testutils.LoadCctxByNonce(t, chain.ChainId, 6270)
1817

1918
// create config
2019
cfg := config.Config{
@@ -24,29 +23,29 @@ func TestCctxRestricted(t *testing.T) {
2423
t.Run("should return true if sender is restricted", func(t *testing.T) {
2524
cfg.ComplianceConfig.RestrictedAddresses = []string{cctx.InboundTxParams.Sender}
2625
config.LoadComplianceConfig(cfg)
27-
require.True(t, IsCctxRestricted(&cctx))
26+
require.True(t, IsCctxRestricted(cctx))
2827
})
2928
t.Run("should return true if receiver is restricted", func(t *testing.T) {
3029
cfg.ComplianceConfig.RestrictedAddresses = []string{cctx.GetCurrentOutTxParam().Receiver}
3130
config.LoadComplianceConfig(cfg)
32-
require.True(t, IsCctxRestricted(&cctx))
31+
require.True(t, IsCctxRestricted(cctx))
3332
})
3433
t.Run("should return false if sender and receiver are not restricted", func(t *testing.T) {
3534
// restrict other address
3635
cfg.ComplianceConfig.RestrictedAddresses = []string{"0x27104b8dB4aEdDb054fCed87c346C0758Ff5dFB1"}
3736
config.LoadComplianceConfig(cfg)
38-
require.False(t, IsCctxRestricted(&cctx))
37+
require.False(t, IsCctxRestricted(cctx))
3938
})
4039
t.Run("should be able to restrict coinbase address", func(t *testing.T) {
4140
cfg.ComplianceConfig.RestrictedAddresses = []string{ethcommon.Address{}.String()}
4241
config.LoadComplianceConfig(cfg)
4342
cctx.InboundTxParams.Sender = ethcommon.Address{}.String()
44-
require.True(t, IsCctxRestricted(&cctx))
43+
require.True(t, IsCctxRestricted(cctx))
4544
})
4645
t.Run("should ignore empty address", func(t *testing.T) {
4746
cfg.ComplianceConfig.RestrictedAddresses = []string{""}
4847
config.LoadComplianceConfig(cfg)
4948
cctx.InboundTxParams.Sender = ""
50-
require.False(t, IsCctxRestricted(&cctx))
49+
require.False(t, IsCctxRestricted(cctx))
5150
})
5251
}

0 commit comments

Comments
 (0)