Skip to content

Commit

Permalink
refactor: enrich transaction service logs with sender address (#4390)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrekucci authored Oct 11, 2023
1 parent 414fc3b commit 2309ec1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/node/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func InitChain(

transactionMonitor := transaction.NewMonitor(logger, backend, overlayEthAddress, pollingInterval, cancellationDepth)

transactionService, err := transaction.NewService(logger, backend, signer, stateStore, chainID, transactionMonitor)
transactionService, err := transaction.NewService(logger, overlayEthAddress, backend, signer, stateStore, chainID, transactionMonitor)
if err != nil {
return nil, common.Address{}, 0, nil, nil, fmt.Errorf("new transaction service: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type transactionService struct {
}

// NewService creates a new transaction service.
func NewService(logger log.Logger, backend Backend, signer crypto.Signer, store storage.StateStorer, chainID *big.Int, monitor Monitor) (Service, error) {
func NewService(logger log.Logger, overlayEthAddress common.Address, backend Backend, signer crypto.Signer, store storage.StateStorer, chainID *big.Int, monitor Monitor) (Service, error) {
senderAddress, err := signer.EthereumAddress()
if err != nil {
return nil, err
Expand All @@ -123,7 +123,7 @@ func NewService(logger log.Logger, backend Backend, signer crypto.Signer, store
t := &transactionService{
ctx: ctx,
cancel: cancel,
logger: logger.WithName(loggerName).Register(),
logger: logger.WithName(loggerName).WithValues("sender_address", overlayEthAddress).Register(),
backend: backend,
signer: signer,
sender: senderAddress,
Expand Down
19 changes: 11 additions & 8 deletions pkg/transaction/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestTransactionSend(t *testing.T) {
t.Fatal(err)
}

transactionService, err := transaction.NewService(logger,
transactionService, err := transaction.NewService(logger, sender,
backendmock.New(
backendmock.WithSendTransactionFunc(func(ctx context.Context, tx *types.Transaction) error {
if tx != signedTx {
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestTransactionSend(t *testing.T) {
t.Fatal(err)
}

transactionService, err := transaction.NewService(logger,
transactionService, err := transaction.NewService(logger, sender,
backendmock.New(
backendmock.WithSendTransactionFunc(func(ctx context.Context, tx *types.Transaction) error {
if tx != signedTx {
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestTransactionSend(t *testing.T) {
}
store := storemock.NewStateStore()

transactionService, err := transaction.NewService(logger,
transactionService, err := transaction.NewService(logger, sender,
backendmock.New(
backendmock.WithSendTransactionFunc(func(ctx context.Context, tx *types.Transaction) error {
if tx != signedTx {
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestTransactionSend(t *testing.T) {
t.Fatal(err)
}

transactionService, err := transaction.NewService(logger,
transactionService, err := transaction.NewService(logger, sender,
backendmock.New(
backendmock.WithSendTransactionFunc(func(ctx context.Context, tx *types.Transaction) error {
if tx != signedTx {
Expand Down Expand Up @@ -505,6 +505,7 @@ func TestTransactionWaitForReceipt(t *testing.T) {
t.Parallel()

logger := log.Noop
sender := common.HexToAddress("0xddff")
txHash := common.HexToHash("0xabcdee")
chainID := big.NewInt(5)
nonce := uint64(10)
Expand All @@ -519,7 +520,7 @@ func TestTransactionWaitForReceipt(t *testing.T) {
t.Fatal(err)
}

transactionService, err := transaction.NewService(logger,
transactionService, err := transaction.NewService(logger, sender,
backendmock.New(
backendmock.WithTransactionReceiptFunc(func(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
return &types.Receipt{
Expand Down Expand Up @@ -565,6 +566,7 @@ func TestTransactionResend(t *testing.T) {
t.Parallel()

logger := log.Noop
sender := common.HexToAddress("0xddff")
recipient := common.HexToAddress("0xbbbddd")
chainID := big.NewInt(5)
nonce := uint64(10)
Expand Down Expand Up @@ -601,7 +603,7 @@ func TestTransactionResend(t *testing.T) {
t.Fatal(err)
}

transactionService, err := transaction.NewService(logger,
transactionService, err := transaction.NewService(logger, sender,
backendmock.New(
backendmock.WithSendTransactionFunc(func(ctx context.Context, tx *types.Transaction) error {
if tx != signedTx {
Expand Down Expand Up @@ -636,6 +638,7 @@ func TestTransactionCancel(t *testing.T) {
t.Parallel()

logger := log.Noop
sender := common.HexToAddress("0xddff")
recipient := common.HexToAddress("0xbbbddd")
chainID := big.NewInt(5)
nonce := uint64(10)
Expand Down Expand Up @@ -690,7 +693,7 @@ func TestTransactionCancel(t *testing.T) {
Data: []byte{},
})

transactionService, err := transaction.NewService(logger,
transactionService, err := transaction.NewService(logger, sender,
backendmock.New(
backendmock.WithSendTransactionFunc(func(ctx context.Context, tx *types.Transaction) error {
if tx != cancelTx {
Expand Down Expand Up @@ -741,7 +744,7 @@ func TestTransactionCancel(t *testing.T) {
Data: []byte{},
})

transactionService, err := transaction.NewService(logger,
transactionService, err := transaction.NewService(logger, sender,
backendmock.New(
backendmock.WithSendTransactionFunc(func(ctx context.Context, tx *types.Transaction) error {
if tx != cancelTx {
Expand Down

0 comments on commit 2309ec1

Please sign in to comment.