From 3d698c06771b0fd8e646e8599b35b5f1a674e428 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Thu, 20 Jan 2022 02:00:22 -0800 Subject: [PATCH 1/3] invariant fix --- vm/vm.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/vm/vm.go b/vm/vm.go index 72fc82dd..87676223 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -340,17 +340,25 @@ func (vm *VM) GetStatelessBlock(blkID ids.ID) (*chain.StatelessBlock, error) { // implements "snowmanblock.ChainVM.commom.VM.Parser" // replaces "core.SnowmanVM.ParseBlock" func (vm *VM) ParseBlock(source []byte) (snowman.Block, error) { - blk, err := chain.ParseBlock( + newBlk, err := chain.ParseBlock( source, choices.Processing, vm, ) if err != nil { log.Error("could not parse block", "err", err) + return nil, err } else { - log.Debug("parsed block", "id", blk.ID()) + log.Debug("parsed block", "id", newBlk.ID()) + } + + // If we have seen this block before, return it with the most + // up-to-date info + if oldBlk, err := vm.GetBlock(newBlk.ID()); err == nil { + return oldBlk, nil } - return blk, err + + return newBlk, nil } // implements "snowmanblock.ChainVM" From 2c553deaeda05c119ac94e42522913a8e3548a2d Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Thu, 20 Jan 2022 02:02:17 -0800 Subject: [PATCH 2/3] nits --- vm/vm.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vm/vm.go b/vm/vm.go index 87676223..d87a2bfb 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -348,9 +348,8 @@ func (vm *VM) ParseBlock(source []byte) (snowman.Block, error) { if err != nil { log.Error("could not parse block", "err", err) return nil, err - } else { - log.Debug("parsed block", "id", newBlk.ID()) } + log.Debug("parsed block", "id", newBlk.ID()) // If we have seen this block before, return it with the most // up-to-date info From e81fbd15eac11e3537d3088779d5f092540a2a7f Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Thu, 20 Jan 2022 02:03:05 -0800 Subject: [PATCH 3/3] add more logs --- vm/vm.go | 1 + 1 file changed, 1 insertion(+) diff --git a/vm/vm.go b/vm/vm.go index d87a2bfb..44226dcf 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -354,6 +354,7 @@ func (vm *VM) ParseBlock(source []byte) (snowman.Block, error) { // If we have seen this block before, return it with the most // up-to-date info if oldBlk, err := vm.GetBlock(newBlk.ID()); err == nil { + log.Debug("returning previously parsed block", "id", oldBlk.ID()) return oldBlk, nil }