Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
NazariiDenha committed Sep 29, 2024
1 parent 0411976 commit 79e3c70
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
4 changes: 2 additions & 2 deletions rollup/internal/config/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ type GasOracleConfig struct {
L1BlobBaseFeeDefault uint64 `json:"l1_blob_base_fee_default"`
}

// SignerConfig - config of signer, contains type and private_key/address,remoteUrl depending on type
// SignerConfig - config of signer, contains type, private key (for PrivateKey type), address and remote URL (for RemoteSigner type)
type SignerConfig struct {
SignerType string `json:"signer_type"` // type of signer can be PrivateKey or RemoteSigner
PrivateKey string `json:"private_key"` // private key of signer in case of PrivateKey signerType
RemoteSignerUrl string `json:"remote_signer_url"` // remote signer url (web3signer) if case of RemoteSigner signerType
RemoteSignerUrl string `json:"remote_signer_url"` // remote signer url (web3signer) in case of RemoteSigner signerType
SignerAddress string `json:"signer_address"` // address of signer
}
38 changes: 38 additions & 0 deletions rollup/internal/controller/relayer/l2_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/scroll-tech/go-ethereum/accounts/abi"
"github.com/scroll-tech/go-ethereum/common"
gethTypes "github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/crypto"
"github.com/scroll-tech/go-ethereum/crypto/kzg4844"
"github.com/scroll-tech/go-ethereum/ethclient"
"github.com/scroll-tech/go-ethereum/log"
Expand Down Expand Up @@ -77,6 +78,25 @@ func NewLayer2Relayer(ctx context.Context, l2Client *ethclient.Client, db *gorm.

var gasOracleSender, commitSender, finalizeSender *sender.Sender
var err error

// check that all 3 signer addresses are different, because there will be a problem in managing nonce for different senders
gasOracleSenderAddr, err := addrFromSignerConfig(cfg.GasOracleSenderSignerConfig)
if err != nil {
return nil, fmt.Errorf("failed to parse addr from gas oracle signer config, err: %v", err)
}
commitSenderAddr, err := addrFromSignerConfig(cfg.CommitSenderSignerConfig)
if err != nil {
return nil, fmt.Errorf("failed to parse addr from commit sender config, err: %v", err)
}
finalizeSenderAddr, err := addrFromSignerConfig(cfg.FinalizeSenderSignerConfig)
if err != nil {
return nil, fmt.Errorf("failed to parse addr from finalize sender config, err: %v", err)
}
if gasOracleSenderAddr == commitSenderAddr || gasOracleSenderAddr == finalizeSenderAddr || commitSenderAddr == finalizeSenderAddr {
return nil, fmt.Errorf("gas oracle, commit, and finalize sender addresses must be different. Got: Gas Oracle=%s, Commit=%s, Finalize=%s",
gasOracleSenderAddr.Hex(), commitSenderAddr.Hex(), finalizeSenderAddr.Hex())
}

switch serviceType {
case ServiceTypeL2GasOracle:
gasOracleSender, err = sender.NewSender(ctx, cfg.SenderConfig, cfg.GasOracleSenderSignerConfig, "l2_relayer", "gas_oracle_sender", types.SenderTypeL2GasOracle, db, reg)
Expand Down Expand Up @@ -1278,3 +1298,21 @@ func (r *Layer2Relayer) StopSenders() {
r.finalizeSender.Stop()
}
}

func addrFromSignerConfig(config *config.SignerConfig) (common.Address, error) {
switch config.SignerType {
case sender.PrivateKeySignerType:
privKey, err := crypto.ToECDSA(common.FromHex(config.PrivateKey))
if err != nil {
return common.Address{}, fmt.Errorf("parse sender private key failed: %w", err)
}
return crypto.PubkeyToAddress(privKey.PublicKey), nil
case sender.RemoteSignerSignerType:
if config.SignerAddress == "" {
return common.Address{}, fmt.Errorf("signer address is empty")
}
return common.HexToAddress(config.SignerAddress), nil
default:
return common.Address{}, fmt.Errorf("failed to determine signer address, unknown signer type: %v", config.SignerType)
}
}
14 changes: 6 additions & 8 deletions rollup/internal/controller/sender/transaction_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"fmt"
"math/big"

"scroll-tech/rollup/internal/config"

"github.com/scroll-tech/go-ethereum/accounts/abi/bind"
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/common/hexutil"
gethTypes "github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/crypto"
"github.com/scroll-tech/go-ethereum/log"

"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/rpc"

"scroll-tech/rollup/internal/config"
)

const (
Expand Down Expand Up @@ -46,10 +45,9 @@ func NewTransactionSigner(config *config.SignerConfig, chainID *big.Int) (*Trans
return nil, fmt.Errorf("failed to create transactor with chain ID %v, err: %w", chainID, err)
}
return &TransactionSigner{
config: config,
auth: auth,
rpcClient: nil,
addr: crypto.PubkeyToAddress(privKey.PublicKey),
config: config,
auth: auth,
addr: crypto.PubkeyToAddress(privKey.PublicKey),
}, nil
case RemoteSignerSignerType:
if config.SignerAddress == "" {
Expand Down
7 changes: 4 additions & 3 deletions rollup/internal/controller/sender/transaction_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"context"
"math/big"
"os"
"scroll-tech/common/testcontainers"
"testing"

"scroll-tech/rollup/internal/config"

"github.com/holiman/uint256"
"github.com/scroll-tech/go-ethereum/common"
gethTypes "github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/log"
"github.com/stretchr/testify/assert"

"scroll-tech/common/testcontainers"

"scroll-tech/rollup/internal/config"
)

var (
Expand Down

0 comments on commit 79e3c70

Please sign in to comment.