diff --git a/tests/fixture/e2e/helpers.go b/tests/fixture/e2e/helpers.go index ee4bcf9b848a..7a6bbbbc378b 100644 --- a/tests/fixture/e2e/helpers.go +++ b/tests/fixture/e2e/helpers.go @@ -19,7 +19,6 @@ import ( "go.uber.org/zap" "github.com/ava-labs/avalanchego/config" - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/tests" "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" @@ -76,25 +75,7 @@ func NewWallet(tc tests.TestContext, keychain *secp256k1fx.Keychain, nodeURI tmp require.NoError(tc, err) wallet := primary.NewWalletWithOptions( baseWallet, - common.WithPostIssuanceHandler( - func(walletID rune, txID ids.ID, duration time.Duration) { - tc.Log().Info("issued transaction", - zap.String("walletID", string(walletID)), - zap.Stringer("txID", txID), - zap.Duration("duration", duration), - ) - }, - ), - common.WithPostConfirmationHandler( - func(walletID rune, txID ids.ID, totalDuration time.Duration, issuanceToConfirmationDuration time.Duration) { - tc.Log().Info("confirmed transaction", - zap.String("walletID", string(walletID)), - zap.Stringer("txID", txID), - zap.Duration("totalDuration", totalDuration), - zap.Duration("issuanceToConfirmationDuration", issuanceToConfirmationDuration), - ) - }, - ), + common.WithLoggedIssuranceAndConfirmation(tc.Log()), // Use a low poll frequency to ensure more accurate determination of confirmation duration common.WithPollFrequency(10*time.Millisecond), ) diff --git a/vms/platformvm/txs/txstest/wallet.go b/vms/platformvm/txs/txstest/wallet.go index 81bd4b0888ca..649bdde366c6 100644 --- a/vms/platformvm/txs/txstest/wallet.go +++ b/vms/platformvm/txs/txstest/wallet.go @@ -129,7 +129,7 @@ func (c *client) IssueTx( ops := common.NewOptions(options) if f := ops.PostIssuanceHandler(); f != nil { txID := tx.ID() - f('P', txID, time.Duration(0)) + f(common.PChainAlias, txID, time.Duration(0)) } ctx := ops.Context() return c.backend.AcceptTx(ctx, tx) diff --git a/wallet/chain/c/wallet.go b/wallet/chain/c/wallet.go index 6f1edf165552..46abae310b86 100644 --- a/wallet/chain/c/wallet.go +++ b/wallet/chain/c/wallet.go @@ -21,8 +21,6 @@ import ( var _ Wallet = (*wallet)(nil) -const WalletID = 'C' - type Wallet interface { // Builder returns the builder that will be used to create the transactions. Builder() Builder @@ -159,7 +157,7 @@ func (w *wallet) IssueAtomicTx( } if f := ops.PostIssuanceHandler(); f != nil { - f(WalletID, txID, issuanceDuration) + f(common.PChainAlias, txID, issuanceDuration) } if ops.AssumeDecided() { @@ -173,7 +171,7 @@ func (w *wallet) IssueAtomicTx( issuanceToConfirmationDuration := totalDuration - issuanceDuration if f := ops.PostConfirmationHandler(); f != nil { - f(WalletID, txID, totalDuration, issuanceToConfirmationDuration) + f(common.CChainAlias, txID, totalDuration, issuanceToConfirmationDuration) } return w.Backend.AcceptAtomicTx(ctx, tx) diff --git a/wallet/chain/p/client.go b/wallet/chain/p/client.go index 5fb0d4c66370..180040b2b06f 100644 --- a/wallet/chain/p/client.go +++ b/wallet/chain/p/client.go @@ -14,7 +14,7 @@ import ( var _ wallet.Client = (*Client)(nil) -const WalletID = 'P' +const chainAlias = "P" func NewClient( c platformvm.Client, @@ -45,7 +45,7 @@ func (c *Client) IssueTx( } if f := ops.PostIssuanceHandler(); f != nil { - f(WalletID, txID, issuanceDuration) + f(chainAlias, txID, issuanceDuration) } if ops.AssumeDecided() { @@ -59,7 +59,7 @@ func (c *Client) IssueTx( issuanceToConfirmationDuration := totalDuration - issuanceDuration if f := ops.PostConfirmationHandler(); f != nil { - f(WalletID, txID, totalDuration, issuanceToConfirmationDuration) + f(chainAlias, txID, totalDuration, issuanceToConfirmationDuration) } return c.backend.AcceptTx(ctx, tx) diff --git a/wallet/chain/x/wallet.go b/wallet/chain/x/wallet.go index 24922580fe9a..d8c7fc6e9afc 100644 --- a/wallet/chain/x/wallet.go +++ b/wallet/chain/x/wallet.go @@ -19,8 +19,6 @@ import ( var _ Wallet = (*wallet)(nil) -const WalletID = 'X' - type Wallet interface { // Builder returns the builder that will be used to create the transactions. Builder() builder.Builder @@ -305,7 +303,7 @@ func (w *wallet) IssueTx( } if f := ops.PostIssuanceHandler(); f != nil { - f(WalletID, txID, issuanceDuration) + f(common.XChainAlias, txID, issuanceDuration) } if ops.AssumeDecided() { @@ -319,7 +317,7 @@ func (w *wallet) IssueTx( issuanceToConfirmationDuration := totalDuration - issuanceDuration if f := ops.PostConfirmationHandler(); f != nil { - f(WalletID, txID, totalDuration, issuanceToConfirmationDuration) + f(common.XChainAlias, txID, totalDuration, issuanceToConfirmationDuration) } return w.backend.AcceptTx(ctx, tx) diff --git a/wallet/subnet/primary/common/options.go b/wallet/subnet/primary/common/options.go index 243539aec4f3..05b51fafbfac 100644 --- a/wallet/subnet/primary/common/options.go +++ b/wallet/subnet/primary/common/options.go @@ -9,18 +9,29 @@ import ( "time" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + "go.uber.org/zap" + ethcommon "github.com/ethereum/go-ethereum/common" ) -const defaultPollFrequency = 100 * time.Millisecond +type PrimaryChainAlias string + +const ( + PChainAlias PrimaryChainAlias = "P" + XChainAlias = "X" + CChainAlias = "C" + + defaultPollFrequency = 100 * time.Millisecond +) // Signature of the function that will be called after a transaction has been issued. type TxIssuanceHandler func( - // Identifies the primary chain ('P', 'X' or 'C') - chainChar rune, + // Identifies the primary chain ("P", "X" or "C") + chainAlias PrimaryChainAlias, // ID of the confirmed transaction txID ids.ID, // The time from initiation to issuance @@ -29,8 +40,8 @@ type TxIssuanceHandler func( // Signature of the function that will be called after a transaction has been confirmed. type TxConfirmationHandler func( - // Identifies the primary chain ('P', 'X' or 'C') - chainChar rune, + // Identifies the primary chain ("P", "X" or "C") + chainAlias PrimaryChainAlias, // ID of the confirmed transaction txID ids.ID, // The time from initiation to confirmation (includes duration of issuance) @@ -234,3 +245,27 @@ func WithPostConfirmationHandler(f TxConfirmationHandler) Option { o.postConfirmationHandler = f } } + +func WithLoggedIssuranceAndConfirmation(log logging.Logger) Option { + return func(o *Options) { + WithPostIssuanceHandler( + func(chainAlias PrimaryChainAlias, txID ids.ID, duration time.Duration) { + log.Info("issued transaction", + zap.String("chainAlias", string(chainAlias)), + zap.Stringer("txID", txID), + zap.Duration("duration", duration), + ) + }, + )(o) + WithPostConfirmationHandler( + func(chainAlias PrimaryChainAlias, txID ids.ID, totalDuration time.Duration, issuanceToConfirmationDuration time.Duration) { + log.Info("confirmed transaction", + zap.String("chainAlias", string(chainAlias)), + zap.Stringer("txID", txID), + zap.Duration("totalDuration", totalDuration), + zap.Duration("issuanceToConfirmationDuration", issuanceToConfirmationDuration), + ) + }, + )(o) + } +}