Skip to content

Commit

Permalink
Use Interface for validitywindow in chain package (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoVillar authored Jan 13, 2025
1 parent 70c155e commit 1699a51
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 0 additions & 4 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ import (
"github.com/ava-labs/avalanchego/x/merkledb"
"github.com/prometheus/client_golang/prometheus"

"github.com/ava-labs/hypersdk/internal/validitywindow"
"github.com/ava-labs/hypersdk/internal/workers"
"github.com/ava-labs/hypersdk/state"
)

// create a type alias for the concrete TimeWindowWindow type.
type ValidityWindow = *validitywindow.TimeValidityWindow[*Transaction]

type Chain struct {
builder *Builder
processor *Processor
Expand Down
17 changes: 17 additions & 0 deletions chain/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"context"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/set"

"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/fees"
"github.com/ava-labs/hypersdk/internal/validitywindow"
"github.com/ava-labs/hypersdk/state"
)

Expand Down Expand Up @@ -204,3 +206,18 @@ type AuthFactory interface {
MaxUnits() (bandwidth uint64, compute uint64)
Address() codec.Address
}

type ValidityWindow interface {
VerifyExpiryReplayProtection(
ctx context.Context,
blk validitywindow.ExecutionBlock[*Transaction],
oldestAllowed int64,
) error
Accept(blk validitywindow.ExecutionBlock[*Transaction])
IsRepeat(
ctx context.Context,
parentBlk validitywindow.ExecutionBlock[*Transaction],
txs []*Transaction,
oldestAllowed int64,
) (set.Bits, error)
}
2 changes: 1 addition & 1 deletion vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type VM struct {
options []Option

chain *chain.Chain
chainTimeValidityWindow chain.ValidityWindow
chainTimeValidityWindow *validitywindow.TimeValidityWindow[*chain.Transaction]
syncer *validitywindow.Syncer[*chain.Transaction]
seenValidityWindowOnce sync.Once
seenValidityWindow chan struct{}
Expand Down

0 comments on commit 1699a51

Please sign in to comment.