Skip to content

Commit

Permalink
Merge branch 'master' into gligneul/download-manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
amsanghi committed Jun 17, 2024
2 parents ee66a14 + cf4b74e commit ad9ac77
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 323 deletions.
54 changes: 51 additions & 3 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/go-redis/redis/v8"
"github.com/holiman/uint256"
"github.com/offchainlabs/nitro/arbnode/dataposter/dbstorage"
"github.com/offchainlabs/nitro/arbnode/dataposter/externalsigner"
"github.com/offchainlabs/nitro/arbnode/dataposter/noop"
"github.com/offchainlabs/nitro/arbnode/dataposter/slice"
"github.com/offchainlabs/nitro/arbnode/dataposter/storage"
Expand Down Expand Up @@ -255,6 +255,50 @@ func rpcClient(ctx context.Context, opts *ExternalSignerCfg) (*rpc.Client, error
)
}

// TxToSignTxArgs converts transaction to SendTxArgs. This is needed for
// external signer to specify From field.
func TxToSignTxArgs(addr common.Address, tx *types.Transaction) (*apitypes.SendTxArgs, error) {
var to *common.MixedcaseAddress
if tx.To() != nil {
to = new(common.MixedcaseAddress)
*to = common.NewMixedcaseAddress(*tx.To())
}
data := (hexutil.Bytes)(tx.Data())
val := (*hexutil.Big)(tx.Value())
if val == nil {
val = (*hexutil.Big)(big.NewInt(0))
}
al := tx.AccessList()
var (
blobs []kzg4844.Blob
commitments []kzg4844.Commitment
proofs []kzg4844.Proof
)
if tx.BlobTxSidecar() != nil {
blobs = tx.BlobTxSidecar().Blobs
commitments = tx.BlobTxSidecar().Commitments
proofs = tx.BlobTxSidecar().Proofs
}
return &apitypes.SendTxArgs{
From: common.NewMixedcaseAddress(addr),
To: to,
Gas: hexutil.Uint64(tx.Gas()),
GasPrice: (*hexutil.Big)(tx.GasPrice()),
MaxFeePerGas: (*hexutil.Big)(tx.GasFeeCap()),
MaxPriorityFeePerGas: (*hexutil.Big)(tx.GasTipCap()),
Value: *val,
Nonce: hexutil.Uint64(tx.Nonce()),
Data: &data,
AccessList: &al,
ChainID: (*hexutil.Big)(tx.ChainId()),
BlobFeeCap: (*hexutil.Big)(tx.BlobGasFeeCap()),
BlobHashes: tx.BlobHashes(),
Blobs: blobs,
Commitments: commitments,
Proofs: proofs,
}, nil
}

// externalSigner returns signer function and ethereum address of the signer.
// Returns an error if address isn't specified or if it can't connect to the
// signer RPC server.
Expand All @@ -273,7 +317,7 @@ func externalSigner(ctx context.Context, opts *ExternalSignerCfg) (signerFn, com
// RLP encoded transaction object.
// https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_signtransaction
var data hexutil.Bytes
args, err := externalsigner.TxToSignTxArgs(addr, tx)
args, err := TxToSignTxArgs(addr, tx)
if err != nil {
return nil, fmt.Errorf("error converting transaction to sendTxArgs: %w", err)
}
Expand All @@ -285,7 +329,11 @@ func externalSigner(ctx context.Context, opts *ExternalSignerCfg) (signerFn, com
return nil, fmt.Errorf("unmarshaling signed transaction: %w", err)
}
hasher := types.LatestSignerForChainID(tx.ChainId())
if h := hasher.Hash(args.ToTransaction()); h != hasher.Hash(signedTx) {
gotTx, err := args.ToTransaction()
if err != nil {
return nil, fmt.Errorf("converting transaction arguments into transaction: %w", err)
}
if h := hasher.Hash(gotTx); h != hasher.Hash(signedTx) {
return nil, fmt.Errorf("transaction: %x from external signer differs from request: %x", hasher.Hash(signedTx), h)
}
return signedTx, nil
Expand Down
7 changes: 1 addition & 6 deletions arbnode/dataposter/dataposter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/google/go-cmp/cmp"
"github.com/holiman/uint256"
"github.com/offchainlabs/nitro/arbnode/dataposter/externalsigner"
"github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest"
"github.com/offchainlabs/nitro/util/arbmath"
)
Expand Down Expand Up @@ -142,11 +141,7 @@ func TestExternalSigner(t *testing.T) {
if err != nil {
t.Fatalf("Error signing transaction with external signer: %v", err)
}
args, err := externalsigner.TxToSignTxArgs(addr, tc.tx)
if err != nil {
t.Fatalf("Error converting transaction to sendTxArgs: %v", err)
}
want, err := srv.SignerFn(addr, args.ToTransaction())
want, err := srv.SignerFn(addr, tc.tx)
if err != nil {
t.Fatalf("Error signing transaction: %v", err)
}
Expand Down
115 changes: 0 additions & 115 deletions arbnode/dataposter/externalsigner/externalsigner.go

This file was deleted.

74 changes: 0 additions & 74 deletions arbnode/dataposter/externalsigner/externalsigner_test.go

This file was deleted.

10 changes: 7 additions & 3 deletions arbnode/dataposter/externalsignertest/externalsignertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
"github.com/offchainlabs/nitro/arbnode/dataposter/externalsigner"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/offchainlabs/nitro/util/testhelpers"
)

Expand Down Expand Up @@ -179,11 +179,15 @@ type SignerAPI struct {
Address common.Address
}

func (a *SignerAPI) SignTransaction(ctx context.Context, req *externalsigner.SignTxArgs) (hexutil.Bytes, error) {
func (a *SignerAPI) SignTransaction(ctx context.Context, req *apitypes.SendTxArgs) (hexutil.Bytes, error) {
if req == nil {
return nil, fmt.Errorf("nil request")
}
signedTx, err := a.SignerFn(a.Address, req.ToTransaction())
tx, err := req.ToTransaction()
if err != nil {
return nil, fmt.Errorf("converting send transaction arguments to transaction: %w", err)
}
signedTx, err := a.SignerFn(a.Address, tx)
if err != nil {
return nil, fmt.Errorf("signing transaction: %w", err)
}
Expand Down
15 changes: 8 additions & 7 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ func createNodeImpl(

var stakerObj *staker.Staker
var messagePruner *MessagePruner
var stakerAddr common.Address

if config.Staker.Enable {
dp, err := StakerDataposter(
Expand Down Expand Up @@ -665,17 +666,12 @@ func createNodeImpl(
if err := wallet.Initialize(ctx); err != nil {
return nil, err
}
var validatorAddr string
if txOptsValidator != nil {
validatorAddr = txOptsValidator.From.String()
} else {
validatorAddr = config.Staker.DataPoster.ExternalSigner.Address
}
stakerAddr = dp.Sender()
whitelisted, err := stakerObj.IsWhitelisted(ctx)
if err != nil {
return nil, err
}
log.Info("running as validator", "txSender", validatorAddr, "actingAsWallet", wallet.Address(), "whitelisted", whitelisted, "strategy", config.Staker.Strategy)
log.Info("running as validator", "txSender", stakerAddr, "actingAsWallet", wallet.Address(), "whitelisted", whitelisted, "strategy", config.Staker.Strategy)
}

var batchPoster *BatchPoster
Expand Down Expand Up @@ -704,6 +700,11 @@ func createNodeImpl(
if err != nil {
return nil, err
}

// Check if staker and batch poster are using the same address
if stakerAddr != (common.Address{}) && !strings.EqualFold(config.Staker.Strategy, "watchtower") && stakerAddr == batchPoster.dataPoster.Sender() {
return nil, fmt.Errorf("staker and batch poster are using the same address which is not allowed: %v", stakerAddr)
}
}

// always create DelayedSequencer, it won't do anything if it is disabled
Expand Down
7 changes: 0 additions & 7 deletions cmd/conf/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
type ParentChainConfig struct {
ID uint64 `koanf:"id"`
Connection rpcclient.ClientConfig `koanf:"connection" reload:"hot"`
Wallet genericconf.WalletConfig `koanf:"wallet"`
BlobClient headerreader.BlobClientConfig `koanf:"blob-client"`
}

Expand All @@ -31,7 +30,6 @@ var L1ConnectionConfigDefault = rpcclient.ClientConfig{
var L1ConfigDefault = ParentChainConfig{
ID: 0,
Connection: L1ConnectionConfigDefault,
Wallet: DefaultL1WalletConfig,
BlobClient: headerreader.DefaultBlobClientConfig,
}

Expand All @@ -46,14 +44,9 @@ var DefaultL1WalletConfig = genericconf.WalletConfig{
func L1ConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Uint64(prefix+".id", L1ConfigDefault.ID, "if set other than 0, will be used to validate database and L1 connection")
rpcclient.RPCClientAddOptions(prefix+".connection", f, &L1ConfigDefault.Connection)
genericconf.WalletConfigAddOptions(prefix+".wallet", f, L1ConfigDefault.Wallet.Pathname)
headerreader.BlobClientAddOptions(prefix+".blob-client", f)
}

func (c *ParentChainConfig) ResolveDirectoryNames(chain string) {
c.Wallet.ResolveDirectoryNames(chain)
}

func (c *ParentChainConfig) Validate() error {
return c.Connection.Validate()
}
Expand Down
Loading

0 comments on commit ad9ac77

Please sign in to comment.