Skip to content

Commit

Permalink
Merge branch 'master' into addgasopcode-stylus-tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower authored Jun 27, 2024
2 parents c103349 + f867ae4 commit 6321019
Show file tree
Hide file tree
Showing 50 changed files with 1,157 additions and 628 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ COPY ./scripts/download-machine.sh .
#RUN ./download-machine.sh consensus-v11 0xf4389b835497a910d7ba3ebfb77aa93da985634f3c052de1290360635be40c4a
#RUN ./download-machine.sh consensus-v11.1 0x68e4fe5023f792d4ef584796c84d710303a5e12ea02d6e37e2b5e9c4332507c4
#RUN ./download-machine.sh consensus-v20 0x8b104a2e80ac6165dc58b9048de12f301d70b02a0ab51396c22b4b4b802a16a4
RUN ./download-machine.sh consensus-v30-rc.2 0xb0de9cb89e4d944ae6023a3b62276e54804c242fd8c4c2d8e6cc4450f5fa8b1b
RUN ./download-machine.sh consensus-v30 0xb0de9cb89e4d944ae6023a3b62276e54804c242fd8c4c2d8e6cc4450f5fa8b1b && true

FROM golang:1.21.10-bookworm as node-builder
WORKDIR /workspace
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ test-go-deps: \
build-replay-env \
$(stylus_test_wasms) \
$(arbitrator_stylus_lib) \
$(arbitrator_generated_header) \
$(patsubst %,$(arbitrator_cases)/%.wasm, global-state read-inboxmsg-10 global-state-wrapper const)

build-prover-header: $(arbitrator_generated_header)
Expand Down
31 changes: 18 additions & 13 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@ var (
baseFeeGauge = metrics.NewRegisteredGauge("arb/batchposter/basefee", nil)
blobFeeGauge = metrics.NewRegisteredGauge("arb/batchposter/blobfee", nil)
l1GasPriceGauge = metrics.NewRegisteredGauge("arb/batchposter/l1gasprice", nil)
l1GasPriceEstimateGauge = metrics.NewRegisteredGauge("arb/batchposter/l1gasprice/estimate", nil)
latestBatchSurplusGauge = metrics.NewRegisteredGauge("arb/batchposter/latestbatchsurplus", nil)
blockGasUsedGauge = metrics.NewRegisteredGauge("arb/batchposter/blockgas/used", nil)
blockGasLimitGauge = metrics.NewRegisteredGauge("arb/batchposter/blockgas/limit", nil)
blobGasUsedGauge = metrics.NewRegisteredGauge("arb/batchposter/blobgas/used", nil)
blobGasLimitGauge = metrics.NewRegisteredGauge("arb/batchposter/blobgas/limit", nil)
suggestedTipCapGauge = metrics.NewRegisteredGauge("arb/batchposter/suggestedtipcap", nil)

batchPosterEstimatedBatchBacklogGauge = metrics.NewRegisteredGauge("arb/batchposter/estimated_batch_backlog", nil)

batchPosterDALastSuccessfulActionGauge = metrics.NewRegisteredGauge("arb/batchPoster/action/da_last_success", nil)
batchPosterDASuccessCounter = metrics.NewRegisteredCounter("arb/batchPoster/action/da_success", nil)
batchPosterDAFailureCounter = metrics.NewRegisteredCounter("arb/batchPoster/action/da_failure", nil)

batchPosterFailureCounter = metrics.NewRegisteredCounter("arb/batchPoster/action/failure", nil)

usableBytesInBlob = big.NewInt(int64(len(kzg4844.Blob{}) * 31 / 32))
blobTxBlobGasPerBlob = big.NewInt(params.BlobTxBlobGasPerBlob)
)
Expand Down Expand Up @@ -560,9 +566,7 @@ func (b *BatchPoster) pollForL1PriceData(ctx context.Context) {
} else {
suggestedTipCapGauge.Update(suggestedTipCap.Int64())
}
l1GasPriceEstimate := b.streamer.CurrentEstimateOfL1GasPrice()
l1GasPriceGauge.Update(int64(l1GasPrice))
l1GasPriceEstimateGauge.Update(int64(l1GasPriceEstimate))
case <-ctx.Done():
return
}
Expand Down Expand Up @@ -1243,6 +1247,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
// don't post anything for now
return false, nil
}

sequencerMsg, err := b.building.segments.CloseAndGetBytes()
if err != nil {
return false, err
Expand All @@ -1260,15 +1265,21 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)

gotNonce, gotMeta, err := b.dataPoster.GetNextNonceAndMeta(ctx)
if err != nil {
batchPosterDAFailureCounter.Inc(1)
return false, err
}
if nonce != gotNonce || !bytes.Equal(batchPositionBytes, gotMeta) {
batchPosterDAFailureCounter.Inc(1)
return false, fmt.Errorf("%w: nonce changed from %d to %d while creating batch", storage.ErrStorageRace, nonce, gotNonce)
}
sequencerMsg, err = b.dapWriter.Store(ctx, sequencerMsg, uint64(time.Now().Add(config.DASRetentionPeriod).Unix()), []byte{}, config.DisableDapFallbackStoreDataOnChain)
sequencerMsg, err = b.dapWriter.Store(ctx, sequencerMsg, uint64(time.Now().Add(config.DASRetentionPeriod).Unix()), config.DisableDapFallbackStoreDataOnChain)
if err != nil {
batchPosterDAFailureCounter.Inc(1)
return false, err
}

batchPosterDASuccessCounter.Inc(1)
batchPosterDALastSuccessfulActionGauge.Update(time.Now().Unix())
}

prevMessageCount := batchPosition.MessageCount
Expand Down Expand Up @@ -1354,14 +1365,6 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
"numBlobs", len(kzgBlobs),
)

surplus := arbmath.SaturatingMul(
arbmath.SaturatingSub(
l1GasPriceGauge.Snapshot().Value(),
l1GasPriceEstimateGauge.Snapshot().Value()),
int64(len(sequencerMsg)*16),
)
latestBatchSurplusGauge.Update(surplus)

recentlyHitL1Bounds := time.Since(b.lastHitL1Bounds) < config.PollInterval*3
postedMessages := b.building.msgCount - batchPosition.MessageCount
b.messagesPerBatch.Update(uint64(postedMessages))
Expand All @@ -1384,6 +1387,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
messagesPerBatch = 1
}
backlog := uint64(unpostedMessages) / messagesPerBatch
batchPosterEstimatedBatchBacklogGauge.Update(int64(backlog))
if backlog > 10 {
logLevel := log.Warn
if recentlyHitL1Bounds {
Expand Down Expand Up @@ -1496,6 +1500,7 @@ func (b *BatchPoster) Start(ctxIn context.Context) {
logLevel = normalGasEstimationFailedEphemeralErrorHandler.LogLevel(err, logLevel)
logLevel = accumulatorNotFoundEphemeralErrorHandler.LogLevel(err, logLevel)
logLevel("error posting batch", "err", err)
batchPosterFailureCounter.Inc(1)
return b.config().ErrorDelay
} else if posted {
return 0
Expand Down
64 changes: 61 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 Expand Up @@ -688,6 +736,10 @@ func (p *DataPoster) PostTransaction(ctx context.Context, dataCreatedAt time.Tim
p.mutex.Lock()
defer p.mutex.Unlock()

if p.config().DisableNewTx {
return nil, fmt.Errorf("posting new transaction is disabled")
}

var weight uint64 = 1
if len(kzgBlobs) > 0 {
weight = uint64(len(kzgBlobs))
Expand Down Expand Up @@ -1208,6 +1260,9 @@ type DataPosterConfig struct {
MaxFeeCapFormula string `koanf:"max-fee-cap-formula" reload:"hot"`
ElapsedTimeBase time.Duration `koanf:"elapsed-time-base" reload:"hot"`
ElapsedTimeImportance float64 `koanf:"elapsed-time-importance" reload:"hot"`
// When set, dataposter will not post new batches, but will keep running to
// get existing batches confirmed.
DisableNewTx bool `koanf:"disable-new-tx" reload:"hot"`
}

type ExternalSignerCfg struct {
Expand Down Expand Up @@ -1269,6 +1324,7 @@ func DataPosterConfigAddOptions(prefix string, f *pflag.FlagSet, defaultDataPost
signature.SimpleHmacConfigAddOptions(prefix+".redis-signer", f)
addDangerousOptions(prefix+".dangerous", f)
addExternalSignerOptions(prefix+".external-signer", f)
f.Bool(prefix+".disable-new-tx", defaultDataPosterConfig.DisableNewTx, "disable posting new transactions, data poster will still keep confirming existing batches")
}

func addDangerousOptions(prefix string, f *pflag.FlagSet) {
Expand Down Expand Up @@ -1308,6 +1364,7 @@ var DefaultDataPosterConfig = DataPosterConfig{
MaxFeeCapFormula: "((BacklogOfBatches * UrgencyGWei) ** 2) + ((ElapsedTime/ElapsedTimeBase) ** 2) * ElapsedTimeImportance + TargetPriceGWei",
ElapsedTimeBase: 10 * time.Minute,
ElapsedTimeImportance: 10,
DisableNewTx: false,
}

var DefaultDataPosterConfigForValidator = func() DataPosterConfig {
Expand Down Expand Up @@ -1341,6 +1398,7 @@ var TestDataPosterConfig = DataPosterConfig{
MaxFeeCapFormula: "((BacklogOfBatches * UrgencyGWei) ** 2) + ((ElapsedTime/ElapsedTimeBase) ** 2) * ElapsedTimeImportance + TargetPriceGWei",
ElapsedTimeBase: 10 * time.Minute,
ElapsedTimeImportance: 10,
DisableNewTx: false,
}

var TestDataPosterConfigForValidator = func() DataPosterConfig {
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.

Loading

0 comments on commit 6321019

Please sign in to comment.