Skip to content

Commit 582d3c2

Browse files
authored
Pass block tracker in deserialize block (#4266)
1 parent fd07475 commit 582d3c2

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

simplex/block.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ func computeDigest(bytes []byte) simplex.Digest {
119119
}
120120

121121
type blockDeserializer struct {
122-
parser block.Parser
122+
parser block.Parser
123+
blockTracker *blockTracker
123124
}
124125

125126
func (d *blockDeserializer) DeserializeBlock(ctx context.Context, bytes []byte) (simplex.Block, error) {
@@ -139,11 +140,7 @@ func (d *blockDeserializer) DeserializeBlock(ctx context.Context, bytes []byte)
139140
return nil, err
140141
}
141142

142-
return &Block{
143-
metadata: *md,
144-
vmBlock: vmblock,
145-
digest: computeDigest(bytes),
146-
}, nil
143+
return newBlock(*md, vmblock, d.blockTracker)
147144
}
148145

149146
// blockTracker is used to ensure that blocks are properly rejected, if competing blocks are accepted.

simplex/block_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
func TestBlockSerialization(t *testing.T) {
2525
unexpectedBlockBytes := errors.New("unexpected block bytes")
2626
ctx := context.Background()
27+
genesisBlock := newTestBlock(t, newBlockConfig{})
2728
testBlock := snowmantest.BuildChild(snowmantest.Genesis)
2829

2930
b := &Block{
@@ -33,7 +34,7 @@ func TestBlockSerialization(t *testing.T) {
3334
Epoch: 1,
3435
Round: 1,
3536
Seq: 1,
36-
Prev: [32]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07},
37+
Prev: genesisBlock.digest,
3738
},
3839
}
3940

@@ -86,7 +87,8 @@ func TestBlockSerialization(t *testing.T) {
8687

8788
testVM.ParseBlockF = tt.parseFunc
8889
deserializer := &blockDeserializer{
89-
parser: testVM,
90+
parser: testVM,
91+
blockTracker: newBlockTracker(genesisBlock),
9092
}
9193

9294
// Deserialize the block
@@ -95,6 +97,8 @@ func TestBlockSerialization(t *testing.T) {
9597

9698
if tt.expectedError == nil {
9799
require.Equal(t, b.BlockHeader().ProtocolMetadata, deserializedBlock.BlockHeader().ProtocolMetadata)
100+
_, err := deserializedBlock.Verify(ctx)
101+
require.NoError(t, err)
98102
}
99103
})
100104
}

0 commit comments

Comments
 (0)