From 09aee3cfdee06612a325d0755292b8125f399a1e Mon Sep 17 00:00:00 2001 From: bruce-riley <96066700+bruce-riley@users.noreply.github.com> Date: Tue, 17 Jan 2023 07:30:50 -0600 Subject: [PATCH] Node/Acct: Renaming (#2245) Change-Id: I20783b4ae4e445a54d45280e19332af87336a92a --- devnet/node.yaml | 6 +- node/cmd/guardiand/node.go | 60 +++++++++---------- .../dev.guardian.key | 0 .../dev.wormchain.key | 0 .../{accounting => accountant}/send_obs.go | 6 +- .../accountant.go} | 58 +++++++++--------- .../accountant_test.go} | 34 +++++------ node/pkg/accountant/metrics.go | 50 ++++++++++++++++ .../{accounting => accountant}/submit_obs.go | 12 ++-- .../pkg/{accounting => accountant}/watcher.go | 10 ++-- .../watcher_test.go | 2 +- node/pkg/accounting/metrics.go | 50 ---------------- node/pkg/db/{accounting.go => accountant.go} | 18 +++--- ...{accounting_test.go => accountant_test.go} | 0 node/pkg/p2p/p2p.go | 4 +- node/pkg/processor/processor.go | 8 +-- 16 files changed, 159 insertions(+), 159 deletions(-) rename node/hack/{accounting => accountant}/dev.guardian.key (100%) rename node/hack/{accounting => accountant}/dev.wormchain.key (100%) rename node/hack/{accounting => accountant}/send_obs.go (97%) rename node/pkg/{accounting/accounting.go => accountant/accountant.go} (87%) rename node/pkg/{accounting/accounting_test.go => accountant/accountant_test.go} (90%) create mode 100644 node/pkg/accountant/metrics.go rename node/pkg/{accounting => accountant}/submit_obs.go (96%) rename node/pkg/{accounting => accountant}/watcher.go (95%) rename node/pkg/{accounting => accountant}/watcher_test.go (99%) delete mode 100644 node/pkg/accounting/metrics.go rename node/pkg/db/{accounting.go => accountant.go} (82%) rename node/pkg/db/{accounting_test.go => accountant_test.go} (100%) diff --git a/devnet/node.yaml b/devnet/node.yaml index 9068e3e92..6a69c8eae 100644 --- a/devnet/node.yaml +++ b/devnet/node.yaml @@ -113,11 +113,11 @@ spec: # - /tmp/mounted-keys/wormchain/wormchainKey # - --wormchainKeyPassPhrase # - test0000 - # - --accountingWS + # - --accountantWS # - http://guardian-validator:26657 - # - --accountingContract + # - --accountantContract # - wormhole1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjq4lyjmh - # - --accountingCheckEnabled=true + # - --accountantCheckEnabled=true # - --terraWS # - ws://terra-terrad:26657/websocket # - --terraLCD diff --git a/node/cmd/guardiand/node.go b/node/cmd/guardiand/node.go index 4d4026479..7afd92e9d 100644 --- a/node/cmd/guardiand/node.go +++ b/node/cmd/guardiand/node.go @@ -37,7 +37,7 @@ import ( "github.com/gorilla/mux" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/certusone/wormhole/node/pkg/accounting" + "github.com/certusone/wormhole/node/pkg/accountant" "github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/devnet" "github.com/certusone/wormhole/node/pkg/governor" @@ -146,11 +146,11 @@ var ( wormchainLCD *string wormchainURL *string wormchainKeyPath *string - wormchainKeyPassPhrase *string // TODO Is there a better way to do this?? + wormchainKeyPassPhrase *string - accountingContract *string - accountingWS *string - accountingCheckEnabled *bool + accountantContract *string + accountantWS *string + accountantCheckEnabled *bool aptosRPC *string aptosAccount *string @@ -294,9 +294,9 @@ func init() { wormchainKeyPath = NodeCmd.Flags().String("wormchainKeyPath", "", "path to wormhole-chain private key for signing transactions") wormchainKeyPassPhrase = NodeCmd.Flags().String("wormchainKeyPassPhrase", "", "pass phrase used to unarmor the wormchain key file") - accountingWS = NodeCmd.Flags().String("accountingWS", "", "Websocket used to listen to the accounting smart contract on wormchain") - accountingContract = NodeCmd.Flags().String("accountingContract", "", "Address of the accounting smart contract on wormchain") - accountingCheckEnabled = NodeCmd.Flags().Bool("accountingCheckEnabled", false, "Should accounting be enforced on transfers") + accountantWS = NodeCmd.Flags().String("accountantWS", "", "Websocket used to listen to the accountant smart contract on wormchain") + accountantContract = NodeCmd.Flags().String("accountantContract", "", "Address of the accountant smart contract on wormchain") + accountantCheckEnabled = NodeCmd.Flags().Bool("accountantCheckEnabled", false, "Should accountant be enforced on transfers") aptosRPC = NodeCmd.Flags().String("aptosRPC", "", "aptos RPC URL") aptosAccount = NodeCmd.Flags().String("aptosAccount", "", "aptos account") @@ -955,10 +955,10 @@ func runNode(cmd *cobra.Command, args []string) { } } - // Set up accounting. If the accounting smart contract is configured, we will instantiate accounting and VAAs - // will be passed to it for processing. It will forward all token bridge transfers to the accounting contract. - // If accountingCheckEnabled is set to true, token bridge transfers will not be signed and published until they - // are approved by the accounting smart contract. + // Set up the accountant. If the accountant smart contract is configured, we will instantiate the accountant and VAAs + // will be passed to it for processing. It will forward all token bridge transfers to the accountant contract. + // If accountantCheckEnabled is set to true, token bridge transfers will not be signed and published until they + // are approved by the accountant smart contract. // TODO: Use this once PR #1931 is merged. //acctReadC, acctWriteC := makeChannelPair[*common.MessagePublication](0) @@ -966,43 +966,43 @@ func runNode(cmd *cobra.Command, args []string) { var acctReadC <-chan *common.MessagePublication = acctChan var acctWriteC chan<- *common.MessagePublication = acctChan - var acct *accounting.Accounting - if *accountingContract != "" { - if *accountingWS == "" { - logger.Fatal("acct: if accountingContract is specified, accountingWS is required") + var acct *accountant.Accountant + if *accountantContract != "" { + if *accountantWS == "" { + logger.Fatal("acct: if accountantContract is specified, accountantWS is required") } if *wormchainLCD == "" { - logger.Fatal("acct: if accountingContract is specified, wormchainLCD is required") + logger.Fatal("acct: if accountantContract is specified, wormchainLCD is required") } if wormchainConn == nil { - logger.Fatal("acct: if accountingContract is specified, the wormchain sending connection must be enabled") + logger.Fatal("acct: if accountantContract is specified, the wormchain sending connection must be enabled") } - if *accountingCheckEnabled { - logger.Info("acct: accounting is enabled and will be enforced") + if *accountantCheckEnabled { + logger.Info("acct: accountant is enabled and will be enforced") } else { - logger.Info("acct: accounting is enabled but will not be enforced") + logger.Info("acct: accountant is enabled but will not be enforced") } - env := accounting.MainNetMode + env := accountant.MainNetMode if *testnetMode { - env = accounting.TestNetMode + env = accountant.TestNetMode } else if *unsafeDevMode { - env = accounting.DevNetMode + env = accountant.DevNetMode } - acct = accounting.NewAccounting( + acct = accountant.NewAccountant( rootCtx, logger, db, - *accountingContract, - *accountingWS, + *accountantContract, + *accountantWS, wormchainConn, - *accountingCheckEnabled, + *accountantCheckEnabled, gk, gst, acctWriteC, env, ) } else { - logger.Info("acct: accounting is disabled") + logger.Info("acct: accountant is disabled") } var gov *governor.ChainGovernor @@ -1332,7 +1332,7 @@ func runNode(cmd *cobra.Command, args []string) { if acct != nil { if err := acct.Start(ctx); err != nil { - logger.Fatal("acct: failed to start accounting", zap.Error(err)) + logger.Fatal("acct: failed to start accountant", zap.Error(err)) } } diff --git a/node/hack/accounting/dev.guardian.key b/node/hack/accountant/dev.guardian.key similarity index 100% rename from node/hack/accounting/dev.guardian.key rename to node/hack/accountant/dev.guardian.key diff --git a/node/hack/accounting/dev.wormchain.key b/node/hack/accountant/dev.wormchain.key similarity index 100% rename from node/hack/accounting/dev.wormchain.key rename to node/hack/accountant/dev.wormchain.key diff --git a/node/hack/accounting/send_obs.go b/node/hack/accountant/send_obs.go similarity index 97% rename from node/hack/accounting/send_obs.go rename to node/hack/accountant/send_obs.go index d7072428d..f138cd222 100644 --- a/node/hack/accounting/send_obs.go +++ b/node/hack/accountant/send_obs.go @@ -12,7 +12,7 @@ import ( "os" "time" - "github.com/certusone/wormhole/node/pkg/accounting" + "github.com/certusone/wormhole/node/pkg/accountant" "github.com/certusone/wormhole/node/pkg/common" nodev1 "github.com/certusone/wormhole/node/pkg/proto/node/v1" "github.com/certusone/wormhole/node/pkg/wormconn" @@ -121,7 +121,7 @@ func testSubmit( Payload: Payload, } - txResp, err := accounting.SubmitObservationToContract(ctx, logger, gk, gsIndex, guardianIndex, wormchainConn, contract, &msg) + txResp, err := accountant.SubmitObservationToContract(ctx, logger, gk, gsIndex, guardianIndex, wormchainConn, contract, &msg) if err != nil { logger.Error("acct: failed to broadcast Observation request", zap.String("test", tag), zap.Error(err)) return false @@ -133,7 +133,7 @@ func testSubmit( // return false // } - alreadyCommitted, err := accounting.CheckSubmitObservationResult(txResp) + alreadyCommitted, err := accountant.CheckSubmitObservationResult(txResp) if err != nil { if !errorExpected { logger.Error("acct: unexpected error", zap.String("test", tag), zap.Error(err)) diff --git a/node/pkg/accounting/accounting.go b/node/pkg/accountant/accountant.go similarity index 87% rename from node/pkg/accounting/accounting.go rename to node/pkg/accountant/accountant.go index 4150a781d..9a3ecf429 100644 --- a/node/pkg/accounting/accounting.go +++ b/node/pkg/accountant/accountant.go @@ -1,10 +1,10 @@ -// The accounting package manages the interface to the accounting smart contract on wormchain. It is passed all VAAs before +// The accountant package manages the interface to the accountant smart contract on wormchain. It is passed all VAAs before // they are signed and published. It determines if the VAA is for a token bridge transfer, and if it is, it submits an observation -// request to the accounting contract. When that happens, the VAA is queued up until the accounting contract responds indicating +// request to the accountant contract. When that happens, the VAA is queued up until the accountant contract responds indicating // that the VAA has been approved. If the VAA is approved, this module will forward the VAA back to the processor loop to be signed // and published. -package accounting +package accountant import ( "context" @@ -58,11 +58,11 @@ type ( } ) -// Accounting is the object that manages the interface to the wormchain accounting smart contract. -type Accounting struct { +// Accountant is the object that manages the interface to the wormchain accountant smart contract. +type Accountant struct { ctx context.Context logger *zap.Logger - db db.AccountingDB + db db.AccountantDB contract string wsUrl string wormchainConn *wormconn.ClientConn @@ -80,21 +80,21 @@ type Accounting struct { const subChanSize = 50 -// NewAccounting creates a new instance of the Accounting object. -func NewAccounting( +// NewAccountant creates a new instance of the Accountant object. +func NewAccountant( ctx context.Context, logger *zap.Logger, - db db.AccountingDB, + db db.AccountantDB, contract string, // the address of the smart contract on wormchain wsUrl string, // the URL of the wormchain websocket interface wormchainConn *wormconn.ClientConn, // used for communicating with the smart contract - enforceFlag bool, // whether or not accounting should be enforced + enforceFlag bool, // whether or not accountant should be enforced gk *ecdsa.PrivateKey, // the guardian key used for signing observation requests gst *common.GuardianSetState, // used to get the current guardian set index when sending observation requests - msgChan chan<- *common.MessagePublication, // the channel where transfers received by the accounting runnable should be published + msgChan chan<- *common.MessagePublication, // the channel where transfers received by the accountant runnable should be published env int, // Controls the set of token bridges to be monitored -) *Accounting { - return &Accounting{ +) *Accountant { + return &Accountant{ ctx: ctx, logger: logger, db: db, @@ -113,8 +113,8 @@ func NewAccounting( } } -// Run initializes the accounting module and starts the watcher runnable. -func (acct *Accounting) Start(ctx context.Context) error { +// Run initializes the accountant and starts the watcher runnable. +func (acct *Accountant) Start(ctx context.Context) error { acct.logger.Debug("acct: entering run") acct.pendingTransfersLock.Lock() defer acct.pendingTransfersLock.Unlock() @@ -163,24 +163,24 @@ func (acct *Accounting) Start(ctx context.Context) error { return nil } -func (acct *Accounting) Close() { +func (acct *Accountant) Close() { if acct.wormchainConn != nil { acct.wormchainConn.Close() acct.wormchainConn = nil } } -func (acct *Accounting) FeatureString() string { +func (acct *Accountant) FeatureString() string { if !acct.enforceFlag { return "acct:logonly" } return "acct:enforced" } -// SubmitObservation will submit token bridge transfers to the accounting smart contract. This is called from the processor +// SubmitObservation will submit token bridge transfers to the accountant smart contract. This is called from the processor // loop when a local observation is received from a watcher. It returns true if the observation can be published immediately, -// false if not (because it has been submitted to accounting). -func (acct *Accounting) SubmitObservation(msg *common.MessagePublication) (bool, error) { +// false if not (because it has been submitted to accountant). +func (acct *Accountant) SubmitObservation(msg *common.MessagePublication) (bool, error) { msgId := msg.MessageIDString() acct.logger.Debug("acct: in SubmitObservation", zap.String("msgID", msgId)) // We only care about token bridges. @@ -227,18 +227,18 @@ func (acct *Accounting) SubmitObservation(msg *common.MessagePublication) (bool, // This transaction may take a while. Pass it off to the worker so we don't block the processor. if acct.env != GoTestMode { - acct.logger.Info("acct: submitting transfer to accounting for approval", zap.String("msgID", msgId), zap.Bool("canPublish", !acct.enforceFlag)) + acct.logger.Info("acct: submitting transfer to accountant for approval", zap.String("msgID", msgId), zap.Bool("canPublish", !acct.enforceFlag)) acct.submitObservation(msg) } - // If we are not enforcing accounting, the event can be published. Otherwise we have to wait to hear back from the contract. + // If we are not enforcing accountant, the event can be published. Otherwise we have to wait to hear back from the contract. return !acct.enforceFlag, nil } // AuditPending audits the set of pending transfers for any that have been in the pending state too long. This is called from the processor loop // each timer interval. Any transfers that have been in the pending state too long will be resubmitted. Any that has been retried too many times // will be logged and dropped. -func (acct *Accounting) AuditPendingTransfers() { +func (acct *Accountant) AuditPendingTransfers() { acct.logger.Debug("acct: in AuditPendingTransfers") acct.pendingTransfersLock.Lock() defer acct.pendingTransfersLock.Unlock() @@ -272,8 +272,8 @@ func (acct *Accounting) AuditPendingTransfers() { acct.logger.Debug("acct: leaving AuditPendingTransfers") } -// publishTransfer publishes a pending transfer to the accounting channel and updates the timestamp. It assumes the caller holds the lock. -func (acct *Accounting) publishTransfer(pe *pendingEntry) { +// publishTransfer publishes a pending transfer to the accountant channel and updates the timestamp. It assumes the caller holds the lock. +func (acct *Accountant) publishTransfer(pe *pendingEntry) { if acct.enforceFlag { acct.logger.Debug("acct: publishTransfer: notifying the processor", zap.String("msgId", pe.msgId)) acct.msgChan <- pe.msg @@ -283,7 +283,7 @@ func (acct *Accounting) publishTransfer(pe *pendingEntry) { } // addPendingTransfer adds a pending transfer to both the map and the database. It assumes the caller holds the lock. -func (acct *Accounting) addPendingTransfer(msgId string, msg *common.MessagePublication, digest string) error { +func (acct *Accountant) addPendingTransfer(msgId string, msg *common.MessagePublication, digest string) error { acct.logger.Debug("acct: addPendingTransfer", zap.String("msgId", msgId)) if err := acct.db.AcctStorePendingTransfer(msg); err != nil { return err @@ -296,7 +296,7 @@ func (acct *Accounting) addPendingTransfer(msgId string, msg *common.MessagePubl } // deletePendingTransfer deletes the transfer from both the map and the database. It assumes the caller holds the lock. -func (acct *Accounting) deletePendingTransfer(msgId string) { +func (acct *Accountant) deletePendingTransfer(msgId string) { acct.logger.Debug("acct: deletePendingTransfer", zap.String("msgId", msgId)) if _, exists := acct.pendingTransfers[msgId]; exists { transfersOutstanding.Dec() @@ -309,7 +309,7 @@ func (acct *Accounting) deletePendingTransfer(msgId string) { } // loadPendingTransfers loads any pending transfers that are present in the database. This method assumes the caller holds the lock. -func (acct *Accounting) loadPendingTransfers() error { +func (acct *Accountant) loadPendingTransfers() error { pendingTransfers, err := acct.db.AcctGetData(acct.logger) if err != nil { return err @@ -337,7 +337,7 @@ func (acct *Accounting) loadPendingTransfers() error { // submitObservation sends an observation request to the worker so it can be submited to the contract. // If writing to the channel would block, this function resets the timestamp on the entry so it will be // retried next audit interval. This method assumes the caller holds the lock. -func (acct *Accounting) submitObservation(msg *common.MessagePublication) { +func (acct *Accountant) submitObservation(msg *common.MessagePublication) { select { case acct.subChan <- msg: acct.logger.Debug("acct: submitted observation to channel", zap.String("msgId", msg.MessageIDString())) diff --git a/node/pkg/accounting/accounting_test.go b/node/pkg/accountant/accountant_test.go similarity index 90% rename from node/pkg/accounting/accounting_test.go rename to node/pkg/accountant/accountant_test.go index 518c2f424..01efa01d2 100644 --- a/node/pkg/accounting/accounting_test.go +++ b/node/pkg/accountant/accountant_test.go @@ -1,4 +1,4 @@ -package accounting +package accountant import ( "context" @@ -21,18 +21,18 @@ import ( ) const ( - enforceAccounting = true - dontEnforceAccounting = false + enforceAccountant = true + dontEnforceAccountant = false ) -func newAccountingForTest( +func newAccountantForTest( t *testing.T, ctx context.Context, - accountingCheckEnabled bool, + accountantCheckEnabled bool, acctWriteC chan<- *common.MessagePublication, -) *Accounting { +) *Accountant { logger := zap.NewNop() - var db db.MockAccountingDB + var db db.MockAccountantDB gk := devnet.InsecureDeterministicEcdsaKeyByIndex(ethCrypto.S256(), uint64(0)) @@ -40,14 +40,14 @@ func newAccountingForTest( gs := &common.GuardianSet{} gst.Set(gs) - acct := NewAccounting( + acct := NewAccountant( ctx, logger, &db, - "0xdeadbeef", // accountingContract - "none", // accountingWS + "0xdeadbeef", // accountantContract + "none", // accountantWS nil, // wormchainConn - accountingCheckEnabled, + accountantCheckEnabled, gk, gst, acctWriteC, @@ -101,7 +101,7 @@ func buildMockTransferPayloadBytes( func TestVaaFromUninterestingEmitter(t *testing.T) { ctx := context.Background() acctChan := make(chan *common.MessagePublication, 10) - acct := newAccountingForTest(t, ctx, enforceAccounting, acctChan) + acct := newAccountantForTest(t, ctx, enforceAccountant, acctChan) require.NotNil(t, acct) emitterAddr, _ := vaa.StringToAddress("0x00") @@ -127,7 +127,7 @@ func TestVaaFromUninterestingEmitter(t *testing.T) { func TestVaaForUninterestingPayloadType(t *testing.T) { ctx := context.Background() acctChan := make(chan *common.MessagePublication, 10) - acct := newAccountingForTest(t, ctx, enforceAccounting, acctChan) + acct := newAccountantForTest(t, ctx, enforceAccountant, acctChan) require.NotNil(t, acct) emitterAddr, _ := vaa.StringToAddress("0x0290fb167208af455bb137780163b7b7a9a10c16") @@ -150,10 +150,10 @@ func TestVaaForUninterestingPayloadType(t *testing.T) { assert.Equal(t, 0, len(acct.pendingTransfers)) } -func TestInterestingTransferShouldNotBeBlockedWhenNotEnforcingAccounting(t *testing.T) { +func TestInterestingTransferShouldNotBeBlockedWhenNotEnforcingAccountant(t *testing.T) { ctx := context.Background() acctChan := make(chan *common.MessagePublication, 10) - acct := newAccountingForTest(t, ctx, dontEnforceAccounting, acctChan) + acct := newAccountantForTest(t, ctx, dontEnforceAccountant, acctChan) require.NotNil(t, acct) emitterAddr, _ := vaa.StringToAddress("0000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16") @@ -192,10 +192,10 @@ func TestInterestingTransferShouldNotBeBlockedWhenNotEnforcingAccounting(t *test assert.Equal(t, 0, len(acct.pendingTransfers)) } -func TestInterestingTransferShouldBeBlockedWhenEnforcingAccounting(t *testing.T) { +func TestInterestingTransferShouldBeBlockedWhenEnforcingAccountant(t *testing.T) { ctx := context.Background() acctChan := make(chan *common.MessagePublication, 10) - acct := newAccountingForTest(t, ctx, enforceAccounting, acctChan) + acct := newAccountantForTest(t, ctx, enforceAccountant, acctChan) require.NotNil(t, acct) emitterAddr, _ := vaa.StringToAddress("0000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16") diff --git a/node/pkg/accountant/metrics.go b/node/pkg/accountant/metrics.go new file mode 100644 index 000000000..484d546be --- /dev/null +++ b/node/pkg/accountant/metrics.go @@ -0,0 +1,50 @@ +package accountant + +import ( + "github.com/prometheus/client_golang/prometheus/promauto" + + "github.com/prometheus/client_golang/prometheus" +) + +var ( + transfersOutstanding = promauto.NewGauge( + prometheus.GaugeOpts{ + Name: "global_accountant_transfer_vaas_outstanding", + Help: "Current number of accountant transfers vaas in the pending state", + }) + transfersSubmitted = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "global_accountant_transfer_vaas_submitted", + Help: "Total number of accountant transfer vaas submitted", + }) + transfersApproved = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "global_accountant_transfer_vaas_submitted_and_approved", + Help: "Total number of accountant transfer vaas that were submitted and approved", + }) + eventsReceived = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "global_accountant_events_received", + Help: "Total number of accountant events received from the smart contract", + }) + submitFailures = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "global_accountant_submit_failures", + Help: "Total number of accountant transfer vaas submit failures", + }) + balanceErrors = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "global_accountant_total_balance_errors", + Help: "Total number of balance errors detected by accountant", + }) + digestMismatches = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "global_accountant_total_digest_mismatches", + Help: "Total number of digest mismatches on accountant", + }) + connectionErrors = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "global_accountant_connection_errors_total", + Help: "Total number of connection errors on accountant", + }) +) diff --git a/node/pkg/accounting/submit_obs.go b/node/pkg/accountant/submit_obs.go similarity index 96% rename from node/pkg/accounting/submit_obs.go rename to node/pkg/accountant/submit_obs.go index 5b062166e..b82e9eb98 100644 --- a/node/pkg/accounting/submit_obs.go +++ b/node/pkg/accountant/submit_obs.go @@ -1,4 +1,4 @@ -package accounting +package accountant import ( "context" @@ -21,7 +21,7 @@ import ( "go.uber.org/zap" ) -func (acct *Accounting) worker(ctx context.Context) error { +func (acct *Accountant) worker(ctx context.Context) error { for { select { case <-ctx.Done(): @@ -108,7 +108,7 @@ func (sb SignatureBytes) MarshalJSON() ([]byte, error) { // submitObservationToContract makes a call to the smart contract to submit an observation request. // It should be called from a go routine because it can block. -func (acct *Accounting) submitObservationToContract(msg *common.MessagePublication, gsIndex uint32, guardianIndex uint32) { +func (acct *Accountant) submitObservationToContract(msg *common.MessagePublication, gsIndex uint32, guardianIndex uint32) { msgId := msg.MessageIDString() acct.logger.Debug("acct: in submitObservationToContract", zap.String("msgID", msgId)) txResp, err := SubmitObservationToContract(acct.ctx, acct.logger, acct.gk, gsIndex, guardianIndex, acct.wormchainConn, acct.contract, msg) @@ -173,14 +173,14 @@ func SubmitObservationToContract( bytes, err := json.Marshal(obs) if err != nil { - return nil, fmt.Errorf("acct: failed to marshal accounting observation request: %w", err) + return nil, fmt.Errorf("acct: failed to marshal accountant observation request: %w", err) } digest := vaa.SigningMsg(bytes) sigBytes, err := ethCrypto.Sign(digest.Bytes(), gk) if err != nil { - return nil, fmt.Errorf("acct: failed to sign accounting Observation request: %w", err) + return nil, fmt.Errorf("acct: failed to sign accountant Observation request: %w", err) } sig := SignatureType{Index: guardianIndex, Signature: sigBytes} @@ -195,7 +195,7 @@ func SubmitObservationToContract( msgBytes, err := json.Marshal(msgData) if err != nil { - return nil, fmt.Errorf("acct: failed to marshal accounting observation request: %w", err) + return nil, fmt.Errorf("acct: failed to marshal accountant observation request: %w", err) } subMsg := wasmdtypes.MsgExecuteContract{ diff --git a/node/pkg/accounting/watcher.go b/node/pkg/accountant/watcher.go similarity index 95% rename from node/pkg/accounting/watcher.go rename to node/pkg/accountant/watcher.go index bfd2d22fc..117aa1e53 100644 --- a/node/pkg/accounting/watcher.go +++ b/node/pkg/accountant/watcher.go @@ -1,4 +1,4 @@ -package accounting +package accountant import ( "context" @@ -22,7 +22,7 @@ import ( ) // watcher reads transaction events from the smart contract and publishes them. -func (acct *Accounting) watcher(ctx context.Context) error { +func (acct *Accountant) watcher(ctx context.Context) error { errC := make(chan error) acct.logger.Info("acctwatch: creating watcher", zap.String("url", acct.wsUrl), zap.String("contract", acct.contract)) @@ -51,7 +51,7 @@ func (acct *Accounting) watcher(ctx context.Context) error { 64, // channel capacity ) if err != nil { - return fmt.Errorf("failed to subscribe to accounting events: %w", err) + return fmt.Errorf("failed to subscribe to accountant events: %w", err) } defer func() { if err := tmConn.UnsubscribeAll(ctx, "guardiand"); err != nil { @@ -70,7 +70,7 @@ func (acct *Accounting) watcher(ctx context.Context) error { } // handleEvents handles events from the tendermint client library. -func (acct *Accounting) handleEvents(ctx context.Context, evts <-chan tmCoreTypes.ResultEvent, errC chan error) { +func (acct *Accountant) handleEvents(ctx context.Context, evts <-chan tmCoreTypes.ResultEvent, errC chan error) { defer close(errC) for { @@ -146,7 +146,7 @@ func parseWasmTransfer(logger *zap.Logger, event tmAbci.Event, contractAddress s } // processPendingTransfer takes a WasmTransfer event, determines if we are expecting it, and if so, publishes it. -func (acct *Accounting) processPendingTransfer(xfer *WasmTransfer) { +func (acct *Accountant) processPendingTransfer(xfer *WasmTransfer) { acct.logger.Info("acctwatch: transfer event detected", zap.String("tx_hash", hex.EncodeToString(xfer.TxHashBytes)), zap.Uint32("timestamp", xfer.Timestamp), diff --git a/node/pkg/accounting/watcher_test.go b/node/pkg/accountant/watcher_test.go similarity index 99% rename from node/pkg/accounting/watcher_test.go rename to node/pkg/accountant/watcher_test.go index 275cf91a1..722514e1b 100644 --- a/node/pkg/accounting/watcher_test.go +++ b/node/pkg/accountant/watcher_test.go @@ -1,4 +1,4 @@ -package accounting +package accountant import ( "encoding/hex" diff --git a/node/pkg/accounting/metrics.go b/node/pkg/accounting/metrics.go deleted file mode 100644 index f1e5cce95..000000000 --- a/node/pkg/accounting/metrics.go +++ /dev/null @@ -1,50 +0,0 @@ -package accounting - -import ( - "github.com/prometheus/client_golang/prometheus/promauto" - - "github.com/prometheus/client_golang/prometheus" -) - -var ( - transfersOutstanding = promauto.NewGauge( - prometheus.GaugeOpts{ - Name: "wormhole_accounting_transfer_vaas_outstanding", - Help: "Current number of accounting transfers vaas in the pending state", - }) - transfersSubmitted = promauto.NewCounter( - prometheus.CounterOpts{ - Name: "wormhole_accounting_transfer_vaas_submitted", - Help: "Total number of accounting transfer vaas submitted", - }) - transfersApproved = promauto.NewCounter( - prometheus.CounterOpts{ - Name: "wormhole_accounting_transfer_vaas_submitted_and_approved", - Help: "Total number of accounting transfer vaas that were submitted and approved", - }) - eventsReceived = promauto.NewCounter( - prometheus.CounterOpts{ - Name: "wormhole_accounting_events_received", - Help: "Total number of accounting events received from the smart contract", - }) - submitFailures = promauto.NewCounter( - prometheus.CounterOpts{ - Name: "wormhole_accounting_submit_failures", - Help: "Total number of accounting transfer vaas submit failures", - }) - balanceErrors = promauto.NewCounter( - prometheus.CounterOpts{ - Name: "wormhole_accounting_total_balance_errors", - Help: "Total number of balance errors detected by accounting", - }) - digestMismatches = promauto.NewCounter( - prometheus.CounterOpts{ - Name: "wormhole_accounting_total_digest_mismatches", - Help: "Total number of digest mismatches on accounting", - }) - connectionErrors = promauto.NewCounter( - prometheus.CounterOpts{ - Name: "wormhole_accounting_connection_errors_total", - Help: "Total number of connection errors on accounting", - }) -) diff --git a/node/pkg/db/accounting.go b/node/pkg/db/accountant.go similarity index 82% rename from node/pkg/db/accounting.go rename to node/pkg/db/accountant.go index 8bafec6ae..70ab4fd09 100644 --- a/node/pkg/db/accounting.go +++ b/node/pkg/db/accountant.go @@ -10,24 +10,24 @@ import ( "go.uber.org/zap" ) -type AccountingDB interface { +type AccountantDB interface { AcctStorePendingTransfer(msg *common.MessagePublication) error AcctDeletePendingTransfer(msgId string) error AcctGetData(logger *zap.Logger) ([]*common.MessagePublication, error) } -type MockAccountingDB struct { +type MockAccountantDB struct { } -func (d *MockAccountingDB) AcctStorePendingTransfer(msg *common.MessagePublication) error { +func (d *MockAccountantDB) AcctStorePendingTransfer(msg *common.MessagePublication) error { return nil } -func (d *MockAccountingDB) AcctDeletePendingTransfer(msgId string) error { +func (d *MockAccountantDB) AcctDeletePendingTransfer(msgId string) error { return nil } -func (d *MockAccountingDB) AcctGetData(logger *zap.Logger) ([]*common.MessagePublication, error) { +func (d *MockAccountantDB) AcctGetData(logger *zap.Logger) ([]*common.MessagePublication, error) { return nil, nil } @@ -44,7 +44,7 @@ func acctIsPendingTransfer(keyBytes []byte) bool { return (len(keyBytes) >= acctPendingTransferLen+acctMinMsgIdLen) && (string(keyBytes[0:acctPendingTransferLen]) == acctPendingTransfer) } -// This is called by the accounting module on start up to reload pending transfers. +// This is called by the accountant on start up to reload pending transfers. func (d *Database) AcctGetData(logger *zap.Logger) ([]*common.MessagePublication, error) { pendingTransfers := []*common.MessagePublication{} prefixBytes := []byte(acctPendingTransfer) @@ -71,7 +71,7 @@ func (d *Database) AcctGetData(logger *zap.Logger) ([]*common.MessagePublication pendingTransfers = append(pendingTransfers, &pt) } else { - return fmt.Errorf("unexpected accounting pending transfer key '%s'", string(key)) + return fmt.Errorf("unexpected accountant pending transfer key '%s'", string(key)) } } @@ -92,7 +92,7 @@ func (d *Database) AcctStorePendingTransfer(msg *common.MessagePublication) erro }) if err != nil { - return fmt.Errorf("failed to commit accounting pending transfer for tx %s: %w", msg.MessageIDString(), err) + return fmt.Errorf("failed to commit accountant pending transfer for tx %s: %w", msg.MessageIDString(), err) } return nil @@ -104,7 +104,7 @@ func (d *Database) AcctDeletePendingTransfer(msgId string) error { err := txn.Delete(key) return err }); err != nil { - return fmt.Errorf("failed to delete accounting pending transfer for tx %s: %w", msgId, err) + return fmt.Errorf("failed to delete accountant pending transfer for tx %s: %w", msgId, err) } return nil diff --git a/node/pkg/db/accounting_test.go b/node/pkg/db/accountant_test.go similarity index 100% rename from node/pkg/db/accounting_test.go rename to node/pkg/db/accountant_test.go diff --git a/node/pkg/p2p/p2p.go b/node/pkg/p2p/p2p.go index e12fb9b9c..bd7b3e689 100644 --- a/node/pkg/p2p/p2p.go +++ b/node/pkg/p2p/p2p.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/certusone/wormhole/node/pkg/accounting" + "github.com/certusone/wormhole/node/pkg/accountant" node_common "github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/governor" "github.com/certusone/wormhole/node/pkg/version" @@ -83,7 +83,7 @@ func Run( nodeName string, disableHeartbeatVerify bool, rootCtxCancel context.CancelFunc, - acct *accounting.Accounting, + acct *accountant.Accountant, gov *governor.ChainGovernor, signedGovCfg chan *gossipv1.SignedChainGovernorConfig, signedGovSt chan *gossipv1.SignedChainGovernorStatus, diff --git a/node/pkg/processor/processor.go b/node/pkg/processor/processor.go index 074fd9107..b2e00a4f1 100644 --- a/node/pkg/processor/processor.go +++ b/node/pkg/processor/processor.go @@ -15,7 +15,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "go.uber.org/zap" - "github.com/certusone/wormhole/node/pkg/accounting" + "github.com/certusone/wormhole/node/pkg/accountant" "github.com/certusone/wormhole/node/pkg/common" gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1" "github.com/certusone/wormhole/node/pkg/reporter" @@ -133,7 +133,7 @@ type Processor struct { notifier *discord.DiscordNotifier governor *governor.ChainGovernor - acct *accounting.Accounting + acct *accountant.Accountant acctReadC <-chan *common.MessagePublication pythnetVaas map[string]PythNetVaaEntry } @@ -157,7 +157,7 @@ func NewProcessor( attestationEvents *reporter.AttestationEventReporter, notifier *discord.DiscordNotifier, g *governor.ChainGovernor, - acct *accounting.Accounting, + acct *accountant.Accountant, acctReadC <-chan *common.MessagePublication, ) *Processor { @@ -229,7 +229,7 @@ func (p *Processor) Run(ctx context.Context) error { case k := <-p.acctReadC: if p.acct == nil { - return fmt.Errorf("acct: received an accounting event when accounting is not configured") + return fmt.Errorf("acct: received an accountant event when accountant is not configured") } p.handleMessage(ctx, k) case v := <-p.injectC: