Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,17 @@ func (bw *BlockBuilderWaiter) BuildBlock(ctx context.Context, metadata common.Pr
}

type blockDeserializer struct {
vm VM
msm *metadata.StateMachine
deserializer BlockDeserializer
msm *metadata.StateMachine
}

func (bp *blockDeserializer) DeserializeBlock(ctx context.Context, bytes []byte) (common.Block, error) {
func (bd *blockDeserializer) DeserializeBlock(ctx context.Context, bytes []byte) (common.Block, error) {
var rawBlock metadata.RawBlock
if err := rawBlock.UnmarshalCanoto(bytes); err != nil {
return nil, err
}

block, err := bp.vm.ParseBlock(ctx, rawBlock.InnerBlockBytes)
block, err := bd.deserializer.ParseBlock(ctx, rawBlock.InnerBlockBytes)
if err != nil {
return nil, err
}
Expand All @@ -248,6 +248,6 @@ func (bp *blockDeserializer) DeserializeBlock(ctx context.Context, bytes []byte)
InnerBlock: block,
Metadata: rawBlock.Metadata,
},
msm: bp.msm,
msm: bd.msm,
}, nil
}
5 changes: 2 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ type VM interface {
// WaitForPendingBlock returns when either the given context is cancelled,
// or when the VM signals that a block should be built.
WaitForPendingBlock(ctx context.Context)
}

type BlockDeserializer interface {
// ParseBlock parses the given block bytes into a VMBlock.
ParseBlock(context.Context, []byte) (avalanchego.VMBlock, error)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But in practice, deserializing blocks is a function of the VM.

I am fine with extracting out the ComputeICMEpoch, but I think the ParseBlock should stay.


// ComputeICMEpoch computes the ICM epoch transition given the input parameters.
ComputeICMEpoch(input metadata.ICMEpochInput) metadata.ICMEpochInfo
}

type Storage interface {
Expand Down
18 changes: 10 additions & 8 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ type Config struct {
// WalCreator is the interface to create new write-ahead logs for the simplex instance.
WalCreator wal.Creator
// Storage is the interface to the block storage layer for the simplex instance.
Storage Storage
Logger common.Logger
Sender Sender
WALs []wal.DeletableWAL
VM VM
ID common.NodeID
Storage Storage
Logger common.Logger
Sender Sender
WALs []wal.DeletableWAL
VM VM
ICMETransition metadata.ICMEpochTransition
BlockDeserializer BlockDeserializer
ID common.NodeID
}

type nodeRole byte
Expand Down Expand Up @@ -461,7 +463,7 @@ func (i *Instance) createEpochConfig() (simplex.EpochConfig, error) {
GetPChainHeightForProposing: i.Config.PlatformChain.GetMinimumHeight,
GetPChainHeightForVerifying: i.Config.PlatformChain.GetCurrentHeight,
AuxiliaryInfoApp: &NoopAuxiliaryInfoApp{},
ComputeICMEpoch: i.Config.VM.ComputeICMEpoch,
ComputeICMEpoch: i.Config.ICMETransition,
GetBlock: i.cs.RetrieveBlock,
})
if err != nil {
Expand Down Expand Up @@ -513,7 +515,7 @@ func (i *Instance) createEpochConfig() (simplex.EpochConfig, error) {
Storage: epochAwareStorage,
Comm: comm,
BlockBuilder: blockBuilder,
BlockDeserializer: &blockDeserializer{vm: i.Config.VM, msm: msm},
BlockDeserializer: &blockDeserializer{deserializer: i.Config.BlockDeserializer, msm: msm},
}
return epochConfig, nil
}
Expand Down
4 changes: 3 additions & 1 deletion instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,12 +873,14 @@ func newInstance(t *testing.T, nodeID common.NodeID, storage *MockStorage, net *

// newInstanceWithVM is like newInstance but uses a caller-supplied VM, so a test
// can share one controllable VM across restarts of the same node.
func newInstanceWithVM(t *testing.T, nodeID common.NodeID, storage *MockStorage, net *inMemNetwork, pChain *testPlatformChain, cops *testCryptoOps, genesisBlock *testInnerBlock, vm VM) *Instance {
func newInstanceWithVM(t *testing.T, nodeID common.NodeID, storage *MockStorage, net *inMemNetwork, pChain *testPlatformChain, cops *testCryptoOps, genesisBlock *testInnerBlock, vm *testVM) *Instance {
comm := &networkSender{net: net, self: nodeID}
config := Config{
Logger: testutil.MakeLogger(t, int(nodeID[0])),
ID: nodeID,
VM: vm,
BlockDeserializer: vm,
ICMETransition: vm.ComputeICMEpoch,
Storage: storage,
Sender: comm,
Broadcaster: comm,
Expand Down
Loading