Skip to content
Merged
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
5 changes: 3 additions & 2 deletions factory/consensus/consensusComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data"
crypto "github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-go/testscommon/processMocks"
"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-go/testscommon/processMocks"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/consensus"
retriever "github.com/multiversx/mx-chain-go/dataRetriever"
Expand Down Expand Up @@ -118,7 +119,7 @@ func createMockConsensusComponentsFactoryArgs() consensusComp.ConsensusComponent
},
},
MbProvider: &testsMocks.MiniBlocksProviderStub{},
Store: &genericMocks.ChainStorerMock{},
Store: genericMocks.NewChainStorerMock(0),
},
ProcessComponents: &testsMocks.ProcessComponentsStub{
EpochTrigger: &testsMocks.EpochStartTriggerStub{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi
delegator2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
err = cs.GenerateBlocks(2)
require.Nil(t, err)

log.Info("working with the following addresses",
Expand Down
3 changes: 2 additions & 1 deletion node/chainSimulator/chainSimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
crypto "github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-crypto-go/signing"
"github.com/multiversx/mx-chain-crypto-go/signing/mcl"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/factory"
"github.com/multiversx/mx-chain-go/node/chainSimulator/components"
Expand All @@ -29,7 +31,6 @@ import (
"github.com/multiversx/mx-chain-go/node/chainSimulator/dtos"
chainSimulatorErrors "github.com/multiversx/mx-chain-go/node/chainSimulator/errors"
"github.com/multiversx/mx-chain-go/node/chainSimulator/process"
logger "github.com/multiversx/mx-chain-logger-go"
)

const delaySendTxs = time.Millisecond
Expand Down
35 changes: 26 additions & 9 deletions process/block/metablockProposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,11 @@ func (mp *metaProcessor) ProcessBlockProposal(
return nil, err
}

var execResult data.BaseExecutionResultHandler
if header.IsEpochChangeProposed() {
return mp.processEpochStartProposeBlock(header, body)
// in case of error, will be picked up by the deferred revert
execResult, err = mp.processEpochStartProposeBlock(header, body)
return execResult, err
}

mp.txCoordinator.RequestBlockTransactions(body)
Expand Down Expand Up @@ -398,12 +401,20 @@ func (mp *metaProcessor) ProcessBlockProposal(
return nil, err
}

valStatRootHash, err := mp.updateValidatorStatistics(header)
var valStatRootHash []byte
valStatRootHash, err = mp.updateValidatorStatistics(header)
if err != nil {
return nil, err
}

err = mp.commitState(headerHandler)
var headerHash []byte
headerHash, err = core.CalculateHash(mp.marshalizer, mp.hasher, header)
if err != nil {
return nil, err
}

// in case of error, will be picked up by the deferred revert
execResult, err = mp.collectExecutionResults(headerHash, header, body, valStatRootHash)
if err != nil {
return nil, err
}
Expand All @@ -413,12 +424,12 @@ func (mp *metaProcessor) ProcessBlockProposal(
return nil, err
}

headerHash, err := core.CalculateHash(mp.marshalizer, mp.hasher, header)
err = mp.commitState(headerHandler)
if err != nil {
return nil, err
}

return mp.collectExecutionResults(headerHash, header, body, valStatRootHash)
return execResult, nil
}

func (mp *metaProcessor) processEpochStartProposeBlock(
Expand Down Expand Up @@ -447,7 +458,8 @@ func (mp *metaProcessor) processEpochStartProposeBlock(
return nil, err
}

computedEconomics, err := mp.getComputedEconomics(metaHeader.GetEpoch() + 1)
var computedEconomics *block.Economics
computedEconomics, err = mp.getComputedEconomics(metaHeader.GetEpoch() + 1)
if err != nil {
return nil, err
}
Expand All @@ -462,7 +474,12 @@ func (mp *metaProcessor) processEpochStartProposeBlock(
return nil, err
}

err = mp.commitState(metaHeader)
headerHash, err := core.CalculateHash(mp.marshalizer, mp.hasher, metaHeader)
if err != nil {
return nil, err
}

execResult, err := mp.collectExecutionResultsEpochStartProposal(headerHash, metaHeader, constructedBody, valStatRootHash)
if err != nil {
return nil, err
}
Expand All @@ -472,12 +489,12 @@ func (mp *metaProcessor) processEpochStartProposeBlock(
return nil, err
}

headerHash, err := core.CalculateHash(mp.marshalizer, mp.hasher, metaHeader)
err = mp.commitState(metaHeader)
if err != nil {
return nil, err
}

return mp.collectExecutionResultsEpochStartProposal(headerHash, metaHeader, constructedBody, valStatRootHash)
return execResult, nil
}

func (mp *metaProcessor) updateValidatorStatistics(header data.MetaHeaderHandler) ([]byte, error) {
Expand Down
77 changes: 48 additions & 29 deletions process/block/metablockProposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3222,6 +3222,15 @@ func TestMetaProcessor_processIfFirstBlockAfterEpochStartBlockV3(t *testing.T) {
func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
t.Parallel()

defaultMetaBlockV3 := block.MetaBlockV3{
LastExecutionResult: &block.MetaExecutionResultInfo{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(0),
DevFeesInEpoch: big.NewInt(0),
},
},
}

t.Run("should return ErrNilBlockHeader because of nil metaHeader argument", func(t *testing.T) {
t.Parallel()

Expand All @@ -3244,7 +3253,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
mp, err := blproc.NewMetaProcessor(arguments)
require.Nil(t, err)

_, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, nil)
_, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, nil)
require.Equal(t, process.ErrNilBlockBody, err)
})

Expand All @@ -3257,7 +3266,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
mp, err := blproc.NewMetaProcessor(arguments)
require.Nil(t, err)

_, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{
_, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{
MiniBlocks: []*block.MiniBlock{
{},
},
Expand All @@ -3282,7 +3291,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
})
require.Nil(t, err)

_, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{})
_, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{})
require.Equal(t, expectedErr, err)
})

Expand All @@ -3307,7 +3316,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
require.Nil(t, err)

mp.SetEpochStartData(&blproc.EpochStartDataWrapper{})
_, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{})
_, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{})
require.Equal(t, expectedErr, err)
})

Expand Down Expand Up @@ -3342,7 +3351,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {

mp.SetEpochStartData(&blproc.EpochStartDataWrapper{})

_, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{})
_, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{})
require.Equal(t, expectedErr, err)
})

Expand Down Expand Up @@ -3381,7 +3390,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {

mp.SetEpochStartData(&blproc.EpochStartDataWrapper{})

_, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{})
_, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{})
require.Equal(t, expectedErr, err)
})

Expand Down Expand Up @@ -3416,7 +3425,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {

mp.SetEpochStartData(&blproc.EpochStartDataWrapper{})

_, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{})
_, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{})
require.Equal(t, expectedErr, err)
})

Expand Down Expand Up @@ -3452,7 +3461,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {

mp.SetEpochStartData(&blproc.EpochStartDataWrapper{})

_, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{})
_, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{})
require.Equal(t, expectedErr, err)
})

Expand Down Expand Up @@ -3486,21 +3495,23 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) {
},
})

_, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{
LastExecutionResult: &block.MetaExecutionResultInfo{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(0),
DevFeesInEpoch: big.NewInt(0),
},
},
}, &block.Body{})
_, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{})
require.Nil(t, err)
})
}

func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing.T) {
t.Parallel()

defaultMetaBlockV3 := block.MetaBlockV3{
LastExecutionResult: &block.MetaExecutionResultInfo{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(0),
DevFeesInEpoch: big.NewInt(0),
},
},
}

t.Run("should return ErrNilBaseExecutionResult error on nil last execution result", func(t *testing.T) {
t.Parallel()

Expand All @@ -3513,7 +3524,7 @@ func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing.
})
require.Nil(t, err)

err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&block.MetaBlockV3{})
err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&defaultMetaBlockV3)
require.ErrorContains(t, err, process.ErrNilBaseExecutionResult.Error())
})

Expand All @@ -3529,7 +3540,7 @@ func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing.
})
require.Nil(t, err)

err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&block.MetaBlockV3{})
err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&defaultMetaBlockV3)
require.Equal(t, common.ErrWrongTypeAssertion, err)
})

Expand All @@ -3550,7 +3561,7 @@ func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing.
})
require.Nil(t, err)

err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&block.MetaBlockV3{})
err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&defaultMetaBlockV3)
require.Equal(t, expectedErr, err)
})

Expand Down Expand Up @@ -3578,7 +3589,7 @@ func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing.
})
require.Nil(t, err)

err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&block.MetaBlockV3{})
err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&defaultMetaBlockV3)
require.Equal(t, expectedErr, err)
})

Expand Down Expand Up @@ -3607,7 +3618,7 @@ func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing.
require.Nil(t, err)

mp.SetEpochStartData(&blproc.EpochStartDataWrapper{})
err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&block.MetaBlockV3{})
err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&defaultMetaBlockV3)
require.Nil(t, err)
})
}
Expand Down Expand Up @@ -3854,6 +3865,14 @@ func TestMetaProcessor_collectExecutionResultsEpochStartProposal(t *testing.T) {
func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
t.Parallel()

defaultMetaBlockV3 := block.MetaBlockV3{
LastExecutionResult: &block.MetaExecutionResultInfo{
ExecutionResult: &block.BaseMetaExecutionResult{
AccumulatedFeesInEpoch: big.NewInt(0),
DevFeesInEpoch: big.NewInt(0),
},
},
}
t.Run("should return ErrNilBlockHeader because of nil argument", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -4291,7 +4310,7 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
return &block.MetaExecutionResult{}
},
GetLastExecutedBlockHeaderCalled: func() data.HeaderHandler {
return &block.MetaBlockV3{}
return &defaultMetaBlockV3
},
}

Expand All @@ -4317,9 +4336,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
mp, err := blproc.NewMetaProcessor(arguments)
require.Nil(t, err)

_, err = mp.ProcessBlockProposal(&block.MetaBlockV3{
Nonce: 1,
}, &block.Body{})
newBlock := defaultMetaBlockV3
newBlock.Nonce = 1
_, err = mp.ProcessBlockProposal(&newBlock, &block.Body{})
require.Equal(t, expectedErr, err)
})

Expand All @@ -4332,7 +4351,7 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
return &block.MetaExecutionResult{}
},
GetLastExecutedBlockHeaderCalled: func() data.HeaderHandler {
return &block.MetaBlockV3{}
return &defaultMetaBlockV3
},
}

Expand All @@ -4345,9 +4364,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) {
mp, err := blproc.NewMetaProcessor(arguments)
require.Nil(t, err)

_, err = mp.ProcessBlockProposal(&block.MetaBlockV3{
Nonce: 1,
}, &block.Body{})
newBlock := defaultMetaBlockV3
newBlock.Nonce = 1
_, err = mp.ProcessBlockProposal(&newBlock, &block.Body{})
require.Equal(t, expectedErr, err)
})

Expand Down
14 changes: 8 additions & 6 deletions process/block/shardblockProposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,20 @@ func (sp *shardProcessor) ProcessBlockProposal(
return nil, err
}

errCutoff := sp.blockProcessingCutoffHandler.HandleProcessErrorCutoff(header)
if errCutoff != nil {
return nil, errCutoff
// TODO: should receive the header hash instead of re-computing it
var headerHash []byte
headerHash, err = core.CalculateHash(sp.marshalizer, sp.hasher, header)
if err != nil {
return nil, err
}

// TODO: should receive the header hash instead of re-computing it
headerHash, err := core.CalculateHash(sp.marshalizer, sp.hasher, header)
var executionResult data.BaseExecutionResultHandler
executionResult, err = sp.collectExecutionResults(headerHash, header, body)
if err != nil {
return nil, err
}

executionResult, err := sp.collectExecutionResults(headerHash, header, body)
err = sp.blockProcessingCutoffHandler.HandleProcessErrorCutoff(header)
if err != nil {
return nil, err
}
Expand Down
Loading
Loading