Skip to content

Commit

Permalink
update per CR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsachiherman committed Dec 23, 2024
1 parent 293c6b9 commit b501cec
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 55 deletions.
1 change: 0 additions & 1 deletion internal/validitywindow/validitywindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (v *TimeValidityWindow[Container]) VerifyExpiryReplayProtection(
return fmt.Errorf("%w: duplicate in ancestry", ErrDuplicateContainer)
}
// make sure we have no repeats within the block itself.
// set.Set
blkContainerIDs := set.NewSet[ids.ID](len(blk.Containers()))
for _, container := range blk.Containers() {
id := container.GetID()
Expand Down
24 changes: 12 additions & 12 deletions x/dsmr/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,32 @@ func ParseChunk[T Tx](chunkBytes []byte) (Chunk[T], error) {

// validityWindowBlock bridge the gap between the dsmr's block implementation and the validity window's execution block interface.
type validityWindowBlock struct {
innerBlock Block
certSet set.Set[ids.ID]
Block
certs set.Set[ids.ID]
}

func (e validityWindowBlock) Timestamp() int64 {
return e.innerBlock.Timestamp
return e.Block.Timestamp
}

func (e validityWindowBlock) Height() uint64 {
return e.innerBlock.Height
return e.Block.Height
}

func (e validityWindowBlock) Contains(id ids.ID) bool {
return e.certSet.Contains(id)
return e.certs.Contains(id)
}

func (e validityWindowBlock) Parent() ids.ID {
return e.innerBlock.ParentID
return e.Block.ParentID
}

func (e validityWindowBlock) Containers() []*emapChunkCertificate {
emapChunkCert := make([]*emapChunkCertificate, len(e.innerBlock.ChunkCerts))
for i := range emapChunkCert {
emapChunkCert[i] = &emapChunkCertificate{*e.innerBlock.ChunkCerts[i]}
chunkCerts := make([]*emapChunkCertificate, len(e.Block.ChunkCerts))
for i := range chunkCerts {
chunkCerts[i] = &emapChunkCertificate{*e.Block.ChunkCerts[i]}
}
return emapChunkCert
return chunkCerts
}

func NewValidityWindowBlock(innerBlock Block) validityWindowBlock {
Expand All @@ -142,8 +142,8 @@ func NewValidityWindowBlock(innerBlock Block) validityWindowBlock {
certSet.Add(c.ChunkID)
}
return validityWindowBlock{
innerBlock: innerBlock,
certSet: certSet,
Block: innerBlock,
certs: certSet,
}
}

Expand Down
70 changes: 28 additions & 42 deletions x/dsmr/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,6 @@ var (
chainID = ids.Empty
)

type testValidityWindowChainIndex struct {
blocks map[ids.ID]validitywindow.ExecutionBlock[*emapChunkCertificate]
}

func (t *testValidityWindowChainIndex) GetExecutionBlock(_ context.Context, blkID ids.ID) (validitywindow.ExecutionBlock[*emapChunkCertificate], error) {
if blk, ok := t.blocks[blkID]; ok {
return blk, nil
}
return nil, database.ErrNotFound
}

func (t *testValidityWindowChainIndex) set(blkID ids.ID, blk validitywindow.ExecutionBlock[*emapChunkCertificate]) {
t.blocks[blkID] = blk
}

func newTestValidityWindowChainIndex() *testValidityWindowChainIndex {
return &testValidityWindowChainIndex{
blocks: make(map[ids.ID]validitywindow.ExecutionBlock[*emapChunkCertificate]),
}
}

// Test that chunks can be built through Node.NewChunk
func TestNode_BuildChunk(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -1063,15 +1042,7 @@ func TestDuplicateChunksElimination(t *testing.T) {

node := newTestNode(t)

blk := Block{
ParentID: ids.GenerateTestID(),
Height: 1,
Timestamp: 1,
blkID: ids.GenerateTestID(),
}
r.NoError(node.Accept(context.Background(), blk))

_, chunkCert, err := node.BuildChunk(
_, _, err := node.BuildChunk(
context.Background(),
[]tx{
{
Expand All @@ -1084,15 +1055,9 @@ func TestDuplicateChunksElimination(t *testing.T) {
)
r.NoError(err)

blk = Block{
ParentID: ids.GenerateTestID(),
Height: 2,
Timestamp: 2,
blkID: ids.GenerateTestID(),
ChunkCerts: []*ChunkCertificate{
&chunkCert,
},
}
blk, err := node.BuildBlock(context.Background(), node.LastAccepted, 2)
r.NoError(err)
r.NoError(node.Verify(context.Background(), node.LastAccepted, blk))
r.NoError(node.Accept(context.Background(), blk))

_, err = node.BuildBlock(context.Background(), blk, 3)
Expand Down Expand Up @@ -1671,20 +1636,41 @@ func newNodes(t *testing.T, n int) ([]*Node[tx], *testValidityWindowChainIndex)
codec.Address{},
)
require.NoError(t, err)
indexer.set(node.LastAccepted.GetID(), validityWindowBlock{innerBlock: node.LastAccepted})
indexer.set(node.LastAccepted.GetID(), validityWindowBlock{Block: node.LastAccepted})

blk, err := node.BuildBlock(context.Background(), node.LastAccepted, node.LastAccepted.Timestamp+1)
require.NoError(t, err)

require.NoError(t, node.Verify(context.Background(), node.LastAccepted, blk))
require.NoError(t, node.Accept(context.Background(), blk))
indexer.set(blk.GetID(), validityWindowBlock{innerBlock: blk})
indexer.set(blk.GetID(), validityWindowBlock{Block: blk})

for _, n := range result[1:] {
require.NoError(t, n.Verify(context.Background(), n.LastAccepted, blk))
require.NoError(t, n.Accept(context.Background(), blk))
indexer.set(blk.GetID(), validityWindowBlock{innerBlock: blk})
indexer.set(blk.GetID(), validityWindowBlock{Block: blk})
}

return result, indexer
}

type testValidityWindowChainIndex struct {
blocks map[ids.ID]validitywindow.ExecutionBlock[*emapChunkCertificate]
}

func (t *testValidityWindowChainIndex) GetExecutionBlock(_ context.Context, blkID ids.ID) (validitywindow.ExecutionBlock[*emapChunkCertificate], error) {
if blk, ok := t.blocks[blkID]; ok {
return blk, nil
}
return nil, database.ErrNotFound
}

func (t *testValidityWindowChainIndex) set(blkID ids.ID, blk validitywindow.ExecutionBlock[*emapChunkCertificate]) {
t.blocks[blkID] = blk
}

func newTestValidityWindowChainIndex() *testValidityWindowChainIndex {
return &testValidityWindowChainIndex{
blocks: make(map[ids.ID]validitywindow.ExecutionBlock[*emapChunkCertificate]),
}
}

0 comments on commit b501cec

Please sign in to comment.