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, dsmr #1810

Merged
merged 80 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
e5ecf69
eliminate emapChunk
tsachiherman Nov 22, 2024
ba644c3
update
tsachiherman Nov 22, 2024
2939543
update
tsachiherman Nov 25, 2024
08f0d59
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Nov 25, 2024
659f1fb
update per CR
tsachiherman Nov 25, 2024
921b908
lint
tsachiherman Nov 25, 2024
508cc92
apply requested changes.
tsachiherman Nov 25, 2024
7a3fed6
fix code + test.
tsachiherman Nov 25, 2024
b312a3c
rollback unneeded changes.
tsachiherman Nov 25, 2024
1238460
rename testing chain indexer.
tsachiherman Nov 25, 2024
8c1ab98
update
tsachiherman Nov 25, 2024
f8e42a8
add unit test.
tsachiherman Nov 26, 2024
b000edf
update unit test.
tsachiherman Nov 26, 2024
1d2536e
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Nov 27, 2024
6911f26
lint
tsachiherman Nov 27, 2024
f2816e7
update
tsachiherman Nov 28, 2024
e78f847
lint
tsachiherman Nov 28, 2024
270245a
update
tsachiherman Nov 28, 2024
144ddd4
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Dec 5, 2024
2fa701d
fix few CR feedback.
tsachiherman Dec 5, 2024
2220b5e
add certSet
tsachiherman Dec 6, 2024
39905b9
remove type declaration block.
tsachiherman Dec 6, 2024
d54e1a0
fix tests
tsachiherman Dec 6, 2024
8e83b6d
update
tsachiherman Dec 6, 2024
fdd4639
update
tsachiherman Dec 6, 2024
9e127f1
update
tsachiherman Dec 9, 2024
0f3fe73
create a wrapper for the block in dsmr (#1829)
tsachiherman Dec 9, 2024
fc87f31
update
tsachiherman Dec 10, 2024
cf82891
update
tsachiherman Dec 10, 2024
864acc1
updatge
tsachiherman Dec 10, 2024
d96160e
fix typo
tsachiherman Dec 10, 2024
9ea09b4
undo unwanted changes
tsachiherman Dec 10, 2024
30bcdce
update
tsachiherman Dec 10, 2024
8d52c05
update
tsachiherman Dec 10, 2024
32207b9
update unit test
tsachiherman Dec 12, 2024
5d62af7
update test
tsachiherman Dec 12, 2024
7ca779b
update
tsachiherman Dec 12, 2024
383a7ef
update
tsachiherman Dec 12, 2024
7902a6a
update per review feedback,.
tsachiherman Dec 13, 2024
1f143ea
address feedback.
tsachiherman Dec 19, 2024
6d4f94c
update per cr
tsachiherman Dec 20, 2024
dd419bb
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Dec 20, 2024
c87b033
update
tsachiherman Dec 23, 2024
293c6b9
Merge branch 'tsachi/refactor_validity_window3' of github.com:ava-lab…
tsachiherman Dec 23, 2024
b501cec
update per CR feedback.
tsachiherman Dec 23, 2024
68603db
update per CR
tsachiherman Dec 23, 2024
7e72626
update per feedback.
tsachiherman Dec 23, 2024
7edef6e
update
tsachiherman Dec 23, 2024
185fbf0
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Dec 23, 2024
9759244
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Jan 7, 2025
44a0e8a
initialize chunkCerts during NewValidityWindowBlock
tsachiherman Jan 7, 2025
6b8692f
update
tsachiherman Jan 9, 2025
a43f23a
update
tsachiherman Jan 9, 2025
b4b9267
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Jan 9, 2025
4fe3602
pin rust toolset to use 1.83.0 for now.
tsachiherman Jan 9, 2025
b900fd1
update
tsachiherman Jan 9, 2025
962cb57
update
tsachiherman Jan 9, 2025
745fea9
update
tsachiherman Jan 9, 2025
aad23ac
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Jan 9, 2025
3540422
undo unneeded changes.
tsachiherman Jan 9, 2025
84157c2
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Jan 10, 2025
58ed219
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Jan 13, 2025
8f243b2
update testing
tsachiherman Jan 13, 2025
69c6996
Merge branch 'tsachi/refactor_validity_window3' of github.com:ava-lab…
tsachiherman Jan 13, 2025
2e879bc
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Jan 13, 2025
43d5d4c
update
tsachiherman Jan 13, 2025
c088d7e
update
tsachiherman Jan 13, 2025
fd641ae
lint
tsachiherman Jan 13, 2025
2db87c4
update
tsachiherman Jan 13, 2025
fa3fc67
lint
tsachiherman Jan 13, 2025
c513464
rollback few unneeded empty lines
tsachiherman Jan 14, 2025
4dfe80b
address CR feedback.
tsachiherman Jan 14, 2025
f56f017
lint
tsachiherman Jan 14, 2025
919e852
Update internal/validitywindow/validitywindow_test.go
tsachiherman Jan 15, 2025
e0a910c
Update internal/validitywindow/validitywindow_test.go
tsachiherman Jan 15, 2025
b0f1782
remove unit test
tsachiherman Jan 15, 2025
7f21c2b
Merge branch 'main' into tsachi/refactor_validity_window3
tsachiherman Jan 15, 2025
23219b0
remove the testing for duplicate containerid from chain.ExecutionBlock
tsachiherman Jan 15, 2025
081381b
Merge branch 'tsachi/refactor_validity_window3' of github.com:ava-lab…
tsachiherman Jan 15, 2025
3f81853
update
tsachiherman Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions chain/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,11 @@ func NewExecutionBlock(block *StatelessBlock) (*ExecutionBlock, error) {
}, nil
}

func (b *ExecutionBlock) ContainsTx(id ids.ID) bool {
func (b *ExecutionBlock) Contains(id ids.ID) bool {
return b.txsSet.Contains(id)
}

func (b *ExecutionBlock) Height() uint64 {
return b.Hght
}

func (b *ExecutionBlock) Parent() ids.ID {
return b.Prnt
}

func (b *ExecutionBlock) Timestamp() int64 {
return b.Tmstmp
}

func (b *ExecutionBlock) Txs() []*Transaction {
func (b *ExecutionBlock) GetContainers() []*Transaction {
return b.StatelessBlock.Txs
}

Expand Down
3 changes: 3 additions & 0 deletions chain/stateless_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func (b *StatelessBlock) ID() ids.ID { return b.id }
func (b *StatelessBlock) Bytes() []byte { return b.bytes }
func (b *StatelessBlock) Size() int { return len(b.bytes) }
func (b *StatelessBlock) GetStateRoot() ids.ID { return b.StateRoot }
func (b *StatelessBlock) GetHeight() uint64 { return b.Hght }
func (b *StatelessBlock) GetTimestamp() int64 { return b.Tmstmp }
func (b *StatelessBlock) GetParent() ids.ID { return b.Prnt }

func (b *StatelessBlock) String() string {
return fmt.Sprintf("(BlockID=%s, Height=%d, ParentRoot=%s, Size=%d)", b.id, b.Hght, b.Prnt, len(b.bytes))
Expand Down
10 changes: 5 additions & 5 deletions internal/validitywindow/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
)

type ExecutionBlock[Container emap.Item] interface {
Parent() ids.ID
Timestamp() int64
Height() uint64
Txs() []Container
ContainsTx(ids.ID) bool
Comment on lines -18 to -19
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this rename needed as part of this change? The increased usage of the term container is confusing to me - it's a new term we're using internally in the codebase, and it also is weird because even though it's a generic type T of a evict-able item we refer to it as a container even though it's the emap interface doesn't imply that it contains anything at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

requested by @aaronbuchwald

GetParent() ids.ID
GetTimestamp() int64
GetHeight() uint64
GetContainers() []Container
Contains(ids.ID) bool
}

type ChainIndex[Container emap.Item] interface {
Expand Down
10 changes: 5 additions & 5 deletions internal/validitywindow/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ func (s *Syncer[Container]) start(ctx context.Context, lastAcceptedBlock Executi
parent = s.initialBlock
parents = []ExecutionBlock[Container]{parent}
seenValidityWindow = false
validityWindow = s.getValidityWindow(lastAcceptedBlock.Timestamp())
validityWindow = s.getValidityWindow(lastAcceptedBlock.GetTimestamp())
err error
)
for {
parent, err = s.chainIndex.GetExecutionBlock(ctx, parent.Parent())
parent, err = s.chainIndex.GetExecutionBlock(ctx, parent.GetParent())
if err != nil {
break // If we can't fetch far enough back or we've gone past genesis, execute what we can
}
parents = append(parents, parent)
seenValidityWindow = lastAcceptedBlock.Timestamp()-parent.Timestamp() > validityWindow
seenValidityWindow = lastAcceptedBlock.GetTimestamp()-parent.GetTimestamp() > validityWindow
if seenValidityWindow {
break
}
}

s.initialBlock = parents[len(parents)-1]
if s.initialBlock.Height() == 0 {
if s.initialBlock.GetHeight() == 0 {
seenValidityWindow = true
}
for i := len(parents) - 1; i >= 0; i-- {
Expand All @@ -68,7 +68,7 @@ func (s *Syncer[Container]) Accept(ctx context.Context, blk ExecutionBlock[Conta
if s.initialBlock == nil {
return s.start(ctx, blk)
}
seenValidityWindow := blk.Timestamp()-s.initialBlock.Timestamp() > s.getValidityWindow(blk.Timestamp())
seenValidityWindow := blk.GetTimestamp()-s.initialBlock.GetTimestamp() > s.getValidityWindow(blk.GetTimestamp())
s.timeValidityWindow.Accept(blk)
return seenValidityWindow, nil
}
36 changes: 23 additions & 13 deletions internal/validitywindow/validitywindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"sync"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/trace"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
Expand Down Expand Up @@ -43,32 +44,41 @@ func (v *TimeValidityWindow[Container]) Accept(blk ExecutionBlock[Container]) {
v.lock.Lock()
defer v.lock.Unlock()

evicted := v.seen.SetMin(blk.Timestamp())
evicted := v.seen.SetMin(blk.GetTimestamp())
v.log.Debug("txs evicted from seen", zap.Int("len", len(evicted)))
v.seen.Add(blk.Txs())
v.lastAcceptedBlockHeight = blk.Height()
v.seen.Add(blk.GetContainers())
v.lastAcceptedBlockHeight = blk.GetHeight()
}

func (v *TimeValidityWindow[Container]) VerifyExpiryReplayProtection(
ctx context.Context,
blk ExecutionBlock[Container],
oldestAllowed int64,
) error {
if blk.Height() <= v.lastAcceptedBlockHeight {
if blk.GetHeight() <= v.lastAcceptedBlockHeight {
return nil
}
parent, err := v.chainIndex.GetExecutionBlock(ctx, blk.Parent())
parent, err := v.chainIndex.GetExecutionBlock(ctx, blk.GetParent())
if err != nil {
return err
}

dup, err := v.isRepeat(ctx, parent, oldestAllowed, blk.Txs(), true)
dup, err := v.isRepeat(ctx, parent, oldestAllowed, blk.GetContainers(), true)
if err != nil {
return err
}
if dup.Len() > 0 {
return fmt.Errorf("%w: duplicate in ancestry", ErrDuplicateContainer)
}
// make sure we have no repeats within the block itself.
blkContainerIDs := set.NewSet[ids.ID](len(blk.GetContainers()))
for _, container := range blk.GetContainers() {
id := container.GetID()
if blkContainerIDs.Contains(id) {
return fmt.Errorf("%w: duplicate in block", ErrDuplicateContainer)
}
blkContainerIDs.Add(id)
}
return nil
}

Expand All @@ -85,7 +95,7 @@ func (v *TimeValidityWindow[Container]) isRepeat(
ctx context.Context,
ancestorBlk ExecutionBlock[Container],
oldestAllowed int64,
txs []Container,
containers []Container,
stop bool,
) (set.Bits, error) {
marker := set.NewBits()
Expand All @@ -98,27 +108,27 @@ func (v *TimeValidityWindow[Container]) isRepeat(

var err error
for {
if ancestorBlk.Timestamp() < oldestAllowed {
if ancestorBlk.GetTimestamp() < oldestAllowed {
return marker, nil
}

if ancestorBlk.Height() <= v.lastAcceptedBlockHeight || ancestorBlk.Height() == 0 {
return v.seen.Contains(txs, marker, stop), nil
if ancestorBlk.GetHeight() <= v.lastAcceptedBlockHeight || ancestorBlk.GetHeight() == 0 {
return v.seen.Contains(containers, marker, stop), nil
}

for i, tx := range txs {
for i, container := range containers {
if marker.Contains(i) {
continue
}
if ancestorBlk.ContainsTx(tx.GetID()) {
if ancestorBlk.Contains(container.GetID()) {
marker.Add(i)
if stop {
return marker, nil
}
}
}

ancestorBlk, err = v.chainIndex.GetExecutionBlock(ctx, ancestorBlk.Parent())
ancestorBlk, err = v.chainIndex.GetExecutionBlock(ctx, ancestorBlk.GetParent())
if err != nil {
return marker, err
}
Expand Down
Loading
Loading