Skip to content

Commit

Permalink
switch from view to immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoVillar committed Jan 17, 2025
1 parent 686da59 commit 811920c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
4 changes: 2 additions & 2 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func (c *Chain) AsyncVerify(
func (c *Chain) PreExecute(
ctx context.Context,
parentBlk *ExecutionBlock,
view state.View,
im state.Immutable,
tx *Transaction,
) error {
return c.preExecutor.PreExecute(ctx, parentBlk, view, tx)
return c.preExecutor.PreExecute(ctx, parentBlk, im, tx)
}

func (c *Chain) ParseBlock(ctx context.Context, bytes []byte) (*ExecutionBlock, error) {
Expand Down
6 changes: 3 additions & 3 deletions chain/pre_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func NewPreExecutor(
func (p *PreExecutor) PreExecute(
ctx context.Context,
parentBlk *ExecutionBlock,
view state.View,
im state.Immutable,
tx *Transaction,
) error {
feeRaw, err := view.GetValue(ctx, FeeKey(p.metadataManager.FeePrefix()))
feeRaw, err := im.GetValue(ctx, FeeKey(p.metadataManager.FeePrefix()))
if err != nil {
return fmt.Errorf("%w: %w", ErrFailedToFetchFee, err)
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func (p *PreExecutor) PreExecute(
// Note, [PreExecute] ensures that the pending transaction does not have
// an expiry time further ahead than [ValidityWindow]. This ensures anything
// added to the [Mempool] is immediately executable.
if err := tx.PreExecute(ctx, nextFeeManager, p.balanceHandler, r, view, now); err != nil {
if err := tx.PreExecute(ctx, nextFeeManager, p.balanceHandler, r, im, now); err != nil {
return err
}
return nil
Expand Down
20 changes: 1 addition & 19 deletions chain/pre_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import (
"testing"
"time"

"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/trace"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/x/merkledb"
"github.com/stretchr/testify/require"

"github.com/ava-labs/hypersdk/chain"
Expand Down Expand Up @@ -166,21 +163,6 @@ func TestPreExecutor(t *testing.T) {
r := require.New(t)
ctx := context.Background()

db, err := merkledb.New(
ctx,
memdb.New(),
merkledb.Config{
BranchFactor: merkledb.BranchFactor16,
Tracer: trace.Noop,
},
)
r.NoError(err)

for k, v := range tt.state {
r.NoError(db.Put([]byte(k), v))
}
r.NoError(db.CommitToDB(ctx))

preExecutor := chain.NewPreExecutor(
&ruleFactory,
tt.validityWindow,
Expand All @@ -192,7 +174,7 @@ func TestPreExecutor(t *testing.T) {
preExecutor.PreExecute(
ctx,
nil,
db,
state.ImmutableStorage(tt.state),
tt.tx,
), tt.err,
)
Expand Down

0 comments on commit 811920c

Please sign in to comment.