From 536b9db243e0f5ce7e7c8a189b4769bf7a904372 Mon Sep 17 00:00:00 2001 From: William Law Date: Mon, 22 Apr 2024 15:26:00 -0400 Subject: [PATCH] fix more lints --- chain/builder.go | 36 +++++++++++++++++++----------------- chain/processor.go | 16 +++++++++------- chain/transaction.go | 10 +++++----- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/chain/builder.go b/chain/builder.go index 71ec95575b..3ac33f09e8 100644 --- a/chain/builder.go +++ b/chain/builder.go @@ -339,7 +339,7 @@ func BuildBlock( log.Warn("invalid tx: invalid state keys") return nil } - result, err := tx.Execute( + txResults, err := tx.Execute( ctx, feeManager, reads, @@ -362,29 +362,31 @@ func BuildBlock( defer blockLock.Unlock() // Ensure block isn't too big - if ok, dimension := feeManager.Consume(result.Consumed, maxUnits); !ok { - log.Debug( - "skipping tx: too many units", - zap.Int("dimension", int(dimension)), - zap.Uint64("tx", result.Consumed[dimension]), - zap.Uint64("block units", feeManager.LastConsumed(dimension)), - zap.Uint64("max block units", maxUnits[dimension]), - ) - restore = true + for _, result := range txResults { + if ok, dimension := feeManager.Consume(result.Consumed, maxUnits); !ok { + log.Debug( + "skipping tx: too many units", + zap.Int("dimension", int(dimension)), + zap.Uint64("tx", result.Consumed[dimension]), + zap.Uint64("block units", feeManager.LastConsumed(dimension)), + zap.Uint64("max block units", maxUnits[dimension]), + ) + restore = true - // If we are above the target for the dimension we can't consume, we will - // stop building. This prevents a full mempool iteration looking for the - // "perfect fit". - if feeManager.LastConsumed(dimension) >= targetUnits[dimension] { - stop = true - return errBlockFull + // If we are above the target for the dimension we can't consume, we will + // stop building. This prevents a full mempool iteration looking for the + // "perfect fit". + if feeManager.LastConsumed(dimension) >= targetUnits[dimension] { + stop = true + return errBlockFull + } } } // Update block with new transaction tsv.Commit() b.Txs = append(b.Txs, tx) - results = append(results, result) + results = append(results, txResults...) if tx.WarpMessage != nil { if warpErr == nil { // Add a bit if the warp message was verified diff --git a/chain/processor.go b/chain/processor.go index 3aef2c87a0..8fc451ec6c 100644 --- a/chain/processor.go +++ b/chain/processor.go @@ -41,7 +41,7 @@ func (b *StatelessBlock) Execute( f = fetcher.New(im, numTxs, b.vm.GetStateFetchConcurrency()) e = executor.New(numTxs, b.vm.GetTransactionExecutionCores(), MaxKeyDependencies, b.vm.GetExecutorVerifyRecorder()) ts = tstate.New(numTxs * 2) // TODO: tune this heuristic - results = make([]*Result, numTxs) + results = make([]*Result, 0) ) // Fetch required keys and execute transactions @@ -89,16 +89,18 @@ func (b *StatelessBlock) Execute( return ctx.Err() } } - result, err := tx.Execute(ctx, feeManager, reads, sm, r, tsv, t, ok && warpVerified) + txResults, err := tx.Execute(ctx, feeManager, reads, sm, r, tsv, t, ok && warpVerified) if err != nil { return err } - results[i] = result + results = append(results, txResults...) - // Update block metadata with units actually consumed (if more is consumed than block allows, we will non-deterministically - // exit with an error based on which tx over the limit is processed first) - if ok, d := feeManager.Consume(result.Consumed, r.GetMaxBlockUnits()); !ok { - return fmt.Errorf("%w: %d too large", ErrInvalidUnitsConsumed, d) + for _, result := range txResults { + // Update block metadata with units actually consumed (if more is consumed than block allows, we will non-deterministically + // exit with an error based on which tx over the limit is processed first) + if ok, d := feeManager.Consume(result.Consumed, r.GetMaxBlockUnits()); !ok { + return fmt.Errorf("%w: %d too large", ErrInvalidUnitsConsumed, d) + } } // Commit results to parent [TState] diff --git a/chain/transaction.go b/chain/transaction.go index da3bc3f1bb..45bc153db1 100644 --- a/chain/transaction.go +++ b/chain/transaction.go @@ -536,7 +536,7 @@ func (t *Transaction) Execute( } } - results = append(results, *Result{ + results = append(results, &Result{ Success: success, Output: output, @@ -556,8 +556,8 @@ func (t *Transaction) Marshal(p *codec.Packer) error { } // TODO: do I need all this within the loop? - for idx, action := range t.Actions { - actionID := action.GetActionID(idx, t.id) + for i, action := range t.Actions { + actionID := action.GetActionID(uint8(i), t.id) authID := t.Auth.GetTypeID() t.Base.Marshal(p) var warpBytes []byte @@ -568,7 +568,7 @@ func (t *Transaction) Marshal(p *codec.Packer) error { } } p.PackBytes(warpBytes) - p.PackByte(actionID) + p.PackAddress(actionID) action.Marshal(p) p.PackByte(authID) t.Auth.Marshal(p) @@ -683,7 +683,7 @@ func UnmarshalTx( var tx Transaction tx.Base = base - tx.Action = action + tx.Actions = []Action{action} tx.WarpMessage = warpMessage tx.Auth = auth if err := p.Err(); err != nil {