Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Jan 23, 2024
1 parent 06963b3 commit 07426cf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 37 deletions.
46 changes: 28 additions & 18 deletions bridge-history-api/internal/logic/l1_event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,10 @@ func (e *L1EventParser) ParseL1CrossChainEventLogs(ctx context.Context, logs []t
log.Error("Failed to unpack SentMessage event", "err", err)
return nil, nil, err
}
from := event.Sender.String()
if from == e.cfg.GatewayRouterAddr {
tx, isPending, rpcErr := e.client.TransactionByHash(ctx, vlog.TxHash)
if rpcErr != nil || isPending {
log.Error("Failed to get tx or the tx is still pending", "rpcErr", rpcErr, "isPending", isPending)
return nil, nil, rpcErr
}
if tx.To() != nil && (*tx.To()).String() != e.cfg.GatewayRouterAddr { // EOA -> multisig -> gateway router.
from = (*tx.To()).String()
} else { // EOA -> gateway router.
signer := types.LatestSignerForChainID(new(big.Int).SetUint64(tx.ChainId().Uint64()))
sender, senderErr := signer.Sender(tx)
if senderErr != nil {
log.Error("get sender failed", "chain id", tx.ChainId().Uint64(), "tx hash", tx.Hash().String(), "err", senderErr)
return nil, nil, senderErr
}
from = sender.String()
}
from, err := getRealFromAddress(ctx, event.Sender, e.client, vlog.TxHash, e.cfg.GatewayRouterAddr)
if err != nil {
log.Error("Failed to get real 'from' address", "err", err)
return nil, nil, err
}
l1DepositMessages = append(l1DepositMessages, &orm.CrossMessage{
L1BlockNumber: vlog.BlockNumber,
Expand Down Expand Up @@ -296,3 +282,27 @@ func (e *L1EventParser) ParseL1MessageQueueEventLogs(logs []types.Log, l1Deposit
}
return l1MessageQueueEvents, nil
}

func getRealFromAddress(ctx context.Context, eventSender common.Address, client *ethclient.Client, txHash common.Hash, gatewayRouterAddr string) (string, error) {
from := eventSender.String()
if from == gatewayRouterAddr {
tx, isPending, rpcErr := client.TransactionByHash(ctx, txHash)
if rpcErr != nil || isPending {
log.Error("Failed to get transaction or the transaction is still pending", "rpcErr", rpcErr, "isPending", isPending)
return "", rpcErr
}
// Case 1: deposit/withdraw ETH: EOA -> multisig -> gateway router -> messenger.
if tx.To() != nil && (*tx.To()).String() != gatewayRouterAddr {
return (*tx.To()).String(), nil
}
// Case 2: deposit/withdraw ETH: EOA -> gateway router -> messenger.
signer := types.LatestSignerForChainID(new(big.Int).SetUint64(tx.ChainId().Uint64()))
sender, err := signer.Sender(tx)
if err != nil {
log.Error("Get sender failed", "chain id", tx.ChainId().Uint64(), "tx hash", tx.Hash().String(), "err", err)
return "", err
}
return sender.String(), nil
}
return from, nil
}
23 changes: 4 additions & 19 deletions bridge-history-api/internal/logic/l2_event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package logic

import (
"context"
"math/big"

"github.com/scroll-tech/go-ethereum/common/hexutil"
"github.com/scroll-tech/go-ethereum/core/types"
Expand Down Expand Up @@ -126,24 +125,10 @@ func (e *L2EventParser) ParseL2EventLogs(ctx context.Context, logs []types.Log,
log.Error("Failed to unpack SentMessage event", "err", err)
return nil, nil, err
}
from := event.Sender.String()
if from == e.cfg.GatewayRouterAddr {
tx, isPending, rpcErr := e.client.TransactionByHash(ctx, vlog.TxHash)
if err != nil || isPending {
log.Error("Failed to get tx or the tx is still pending", "rpcErr", rpcErr, "isPending", isPending)
return nil, nil, rpcErr
}
if tx.To() != nil && (*tx.To()).String() != e.cfg.GatewayRouterAddr { // EOA -> multisig -> gateway router.
from = (*tx.To()).String()
} else { // EOA -> gateway router.
signer := types.LatestSignerForChainID(new(big.Int).SetUint64(tx.ChainId().Uint64()))
sender, senderErr := signer.Sender(tx)
if senderErr != nil {
log.Error("get sender failed", "chain id", tx.ChainId().Uint64(), "tx hash", tx.Hash().String(), "err", senderErr)
return nil, nil, senderErr
}
from = sender.String()
}
from, err := getRealFromAddress(ctx, event.Sender, e.client, vlog.TxHash, e.cfg.GatewayRouterAddr)
if err != nil {
log.Error("Failed to get real 'from' address", "err", err)
return nil, nil, err
}
l2WithdrawMessages = append(l2WithdrawMessages, &orm.CrossMessage{
MessageHash: utils.ComputeMessageHash(event.Sender, event.Target, event.Value, event.MessageNonce, event.Message).String(),
Expand Down

0 comments on commit 07426cf

Please sign in to comment.