Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize expiry based de-duplication #1782

Merged
merged 23 commits into from
Nov 21, 2024

Conversation

tsachiherman
Copy link
Contributor

What ?

  • Extract the validity window implementation out of the chain package into it's own internal package.

@@ -7,17 +7,18 @@ import (
"context"

"github.com/ava-labs/avalanchego/trace"
"github.com/ava-labs/hypersdk/internal/validity_window"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we make this validitywindow and avoid underscores?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -41,13 +42,13 @@ func NewExecutionBlock(block *StatelessBlock) *ExecutionBlock {
}
}

func (b *ExecutionBlock) initTxs() error {
if b.txsSet.Len() == len(b.Txs) {
func (b *ExecutionBlock) InitTxs() error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of this extra call by loading the txs set on parse, so that we don't need to push this into the internal validity window package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


var ErrDuplicateTx = errors.New("duplicate transaction")

type ExecutionBlock[TxnTypePtr emap.Item] interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Container instead of TxnTypePtr

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment to the other function names that refer to Tx. We should also use Tx rather than txn as shorthand for txs since we've used that nomenclature throughout the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Timestamp() int64
Height() uint64
Txs() []TxnTypePtr
InitTxs() error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the need for InitTxs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

chain/syncer.go Outdated
Comment on lines 18 to 19
chainIndex validity_window.ChainIndex[*Transaction]
timeValidityWindow validity_window.TimeValidityWindow[*Transaction]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the syncer into the validity window package as well since it is required to find the point where we can safely start to apply de-duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 33 to 34
// create a local name for the imported interface.
type ValidityWindow validitywindow.TimeValidityWindow[*Transaction]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the type alias to where it's used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"github.com/ava-labs/hypersdk/internal/emap"
)

type GetValidityWindowFunc func(int64) int64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this function do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment updated.

Comment on lines 49 to 52
seenValidityWindow = lastAcceptedBlock.Timestamp()-parent.Timestamp() > s.getValidityWindow(lastAcceptedBlock.Timestamp())
if seenValidityWindow {
break
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we calculate the validity window for the accepted block once rather than in each iteration of this loop to improve readability?

"github.com/ava-labs/hypersdk/internal/emap"
)

var ErrDuplicateTx = errors.New("duplicate transaction")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename to ErrDuplicateContainer and update error string to "duplicate container"

v.lock.Lock()
defer v.lock.Unlock()

lastAcceptedBlkHeight := v.chainIndex.LastAcceptedBlockHeight()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not needed for this PR because it's an existing bug) note: we should move tracking the last accepted block internal to the validity window (#1780)

I introduced a subtle bug here where we need to trace back not to the last accepted block, but up to the last block where v.seen has been updated. This is much simpler if we track the last accepted block by updating it and v.seen during Accept.


type ChainIndex[Container emap.Item] interface {
GetExecutionBlock(ctx context.Context, blkID ids.ID) (ExecutionBlock[Container], error)
LastAcceptedBlockHeight() uint64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be able to remove this in favor of tracking the last accepted height from within the validity window

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Comment on lines 38 to 42

// authCounts can be used by batch signature verification
// to preallocate memory
authCounts map[uint8]int
txsSet set.Set[ids.ID]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep this in ExecutionBlock so that we only populate it as needed (ie for blocks that we may verify)?

If we put it here, then every type that uses this type will have to populate these fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@aaronbuchwald aaronbuchwald enabled auto-merge (squash) November 21, 2024 20:01
@aaronbuchwald aaronbuchwald merged commit 07c1df9 into main Nov 21, 2024
17 checks passed
@aaronbuchwald aaronbuchwald deleted the tsachi/refactor_validity_window branch November 21, 2024 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants