Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new blockchain hooks #6319

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a7e9294
add new blockchain hooks
laurci Jul 16, 2024
9ff3ca2
Merge remote-tracking branch 'origin/rc/v1.7.next1' into new-blockcha…
laurci Jul 24, 2024
67a99d6
Merge remote-tracking branch 'origin/rc/v1.7.2' into new-blockchain-h…
laurci Jul 25, 2024
f060fde
use cached epoch start block in vm blockchain hook
laurci Jul 26, 2024
a4b93be
tpn nil epoch start trigger
laurci Jul 26, 2024
c8ef463
use round handler to get round duration in blockchain hook
laurci Jul 26, 2024
9334561
fix nil pointer epoch start block header
laurci Jul 26, 2024
b9eef0c
nil checks for RoundHandler and EpochStartTriggerHandler
laurci Jul 29, 2024
f94bc3c
fix more RoundHandler nils in tests
laurci Jul 29, 2024
8d9114d
deep copy header when returning from trigger
laurci Jul 29, 2024
0684c29
epochStartHdr nil error check
laurci Jul 29, 2024
53f4563
propagate SetCurrentHeader errors
laurci Jul 30, 2024
0534fc4
remove log; epoch start hdr check if nil
laurci Jul 30, 2024
1f07ae2
simplify error handling in LastCommitedEpochStartHdr impl
laurci Jul 31, 2024
1877e0c
get epoch start block from storage for sc query
laurci Jul 31, 2024
6f64220
add comment for SetEpochStartHeader
laurci Aug 1, 2024
a333893
rc/1.7.2 update dependencies
laurci Aug 2, 2024
fc46b8b
managed buffer small ints gas cost
laurci Aug 2, 2024
5d877d8
formatting fixes
laurci Aug 2, 2024
4ac3ab5
update vm version
laurci Aug 2, 2024
a6a1af7
chainsimulator tests fixes
laurci Aug 7, 2024
e770491
more chain simulator tests fixing
laurci Aug 7, 2024
2a402b5
add warn logs for error cases in updateEpochStartHeaderFromCurrentHeader
laurci Aug 14, 2024
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: 5 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
GetCodeMetadata = 10000
IsBuiltinFunction = 10000
IsReservedFunctionName = 10000
GetRoundTime = 1000
EpochStartBlockTimeStamp = 1000
EpochStartBlockNonce = 1000
EpochStartBlockRound = 1000


[EthAPICost]
UseGas = 100
Expand Down
4 changes: 4 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
GetCodeMetadata = 10000
IsBuiltinFunction = 10000
IsReservedFunctionName = 10000
GetRoundTime = 10000
EpochStartBlockTimeStamp = 10000
EpochStartBlockNonce = 10000
EpochStartBlockRound = 10000

[EthAPICost]
UseGas = 100
Expand Down
4 changes: 4 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
GetCodeMetadata = 10000
IsBuiltinFunction = 10000
IsReservedFunctionName = 10000
GetRoundTime = 10000
EpochStartBlockTimeStamp = 10000
EpochStartBlockNonce = 10000
EpochStartBlockRound = 10000

[EthAPICost]
UseGas = 100
Expand Down
4 changes: 4 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV4.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
GetCodeMetadata = 10000
IsBuiltinFunction = 10000
IsReservedFunctionName = 10000
GetRoundTime = 10000
EpochStartBlockTimeStamp = 10000
EpochStartBlockNonce = 10000
EpochStartBlockRound = 10000

[EthAPICost]
UseGas = 100
Expand Down
4 changes: 4 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV5.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
GetCodeMetadata = 10000
IsBuiltinFunction = 10000
IsReservedFunctionName = 10000
GetRoundTime = 10000
EpochStartBlockTimeStamp = 10000
EpochStartBlockNonce = 10000
EpochStartBlockRound = 10000

[EthAPICost]
UseGas = 100
Expand Down
4 changes: 4 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV6.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
GetCodeMetadata = 10000
IsBuiltinFunction = 10000
IsReservedFunctionName = 10000
GetRoundTime = 10000
EpochStartBlockTimeStamp = 10000
EpochStartBlockNonce = 10000
EpochStartBlockRound = 10000

[EthAPICost]
UseGas = 100
Expand Down
4 changes: 4 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV7.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
GetCodeMetadata = 10000
IsBuiltinFunction = 10000
IsReservedFunctionName = 10000
GetRoundTime = 10000
EpochStartBlockTimeStamp = 10000
EpochStartBlockNonce = 10000
EpochStartBlockRound = 10000

[EthAPICost]
UseGas = 100
Expand Down
4 changes: 4 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV8.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
GetCodeMetadata = 10000
IsBuiltinFunction = 10000
IsReservedFunctionName = 10000
GetRoundTime = 10000
EpochStartBlockTimeStamp = 10000
EpochStartBlockNonce = 10000
EpochStartBlockRound = 10000

[EthAPICost]
UseGas = 100
Expand Down
6 changes: 6 additions & 0 deletions epochStart/bootstrap/disabled/disabledEpochStartTrigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package disabled

import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
)

type epochStartTrigger struct {
Expand Down Expand Up @@ -54,6 +55,11 @@ func (e *epochStartTrigger) EpochStartMetaHdrHash() []byte {
return nil
}

// LastCommitedEpochStartHdr -
func (e *epochStartTrigger) LastCommitedEpochStartHdr() (data.HeaderHandler, error) {
return &block.HeaderV2{}, nil
}

// GetSavedStateKey -
func (e *epochStartTrigger) GetSavedStateKey() []byte {
return nil
Expand Down
1 change: 1 addition & 0 deletions epochStart/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type TriggerHandler interface {
Update(round uint64, nonce uint64)
EpochStartRound() uint64
EpochStartMetaHdrHash() []byte
LastCommitedEpochStartHdr() (data.HeaderHandler, error)
GetSavedStateKey() []byte
LoadState(key []byte) error
SetProcessed(header data.HeaderHandler, body data.BodyHandler)
Expand Down
2 changes: 2 additions & 0 deletions epochStart/metachain/systemSCs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,8 @@ func createFullArgumentsForSystemSCProcessing(enableEpochsConfig config.EnableEp
GasSchedule: gasScheduleNotifier,
Counter: &testscommon.BlockChainHookCounterStub{},
MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{},
EpochStartTrigger: &testscommon.EpochStartTriggerStub{},
RoundHandler: &testscommon.RoundHandlerMock{},
}

defaults.FillGasMapInternal(gasSchedule, 1)
Expand Down
16 changes: 15 additions & 1 deletion epochStart/metachain/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-logger-go"
logger "github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("epochStart/metachain")
Expand Down Expand Up @@ -403,6 +403,20 @@ func (t *trigger) EpochStartMetaHdrHash() []byte {
return t.epochStartMetaHash
}

// LastCommitedEpochStartHdr returns the header of the epoch start block
func (t *trigger) LastCommitedEpochStartHdr() (data.HeaderHandler, error) {
t.mutTrigger.RLock()
defer t.mutTrigger.RUnlock()

// marshal + unmarshal deep copy
headerBytes, err := t.marshaller.Marshal(t.epochStartMeta)
if err != nil {
return nil, err
}

return process.UnmarshalMetaHeader(t.marshaller, headerBytes)
}

// GetSavedStateKey returns the last saved trigger state key
func (t *trigger) GetSavedStateKey() []byte {
return t.triggerStateKey
Expand Down
16 changes: 15 additions & 1 deletion epochStart/shardchain/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-logger-go"
logger "github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("epochStart/shardchain")
Expand Down Expand Up @@ -1102,6 +1102,20 @@ func (t *trigger) EpochStartMetaHdrHash() []byte {
return t.epochMetaBlockHash
}

// LastCommitedEpochStartHdr returns the epoch start header
func (t *trigger) LastCommitedEpochStartHdr() (data.HeaderHandler, error) {
t.mutTrigger.RLock()
defer t.mutTrigger.RUnlock()

// marshal + unmarshal deep copy
headerBytes, err := t.marshaller.Marshal(t.epochStartShardHeader)
if err != nil {
return nil, err
}

return process.UnmarshalShardHeader(t.marshaller, headerBytes)
}

// GetSavedStateKey returns the last saved trigger state key
func (t *trigger) GetSavedStateKey() []byte {
return t.triggerStateKey
Expand Down
2 changes: 2 additions & 0 deletions factory/api/apiResolverFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ func createScQueryElement(
MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(),
Accounts: accountsAdapterApi,
BlockChain: apiBlockchain,
EpochStartTrigger: args.processComponents.EpochStartTrigger(),
RoundHandler: args.processComponents.RoundHandler(),
}

var vmFactory process.VirtualMachinesContainerFactory
Expand Down
27 changes: 19 additions & 8 deletions factory/mock/epochStartTriggerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ package mock
import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-go/epochStart"
)

// EpochStartTriggerStub -
type EpochStartTriggerStub struct {
ForceEpochStartCalled func(round uint64)
IsEpochStartCalled func() bool
EpochCalled func() uint32
MetaEpochCalled func() uint32
ReceivedHeaderCalled func(handler data.HeaderHandler)
UpdateCalled func(round uint64, nonce uint64)
ProcessedCalled func(header data.HeaderHandler)
EpochStartRoundCalled func() uint64
ForceEpochStartCalled func(round uint64)
IsEpochStartCalled func() bool
EpochCalled func() uint32
MetaEpochCalled func() uint32
LastCommitedEpochStartHdrCalled func() (data.HeaderHandler, error)
ReceivedHeaderCalled func(handler data.HeaderHandler)
UpdateCalled func(round uint64, nonce uint64)
ProcessedCalled func(header data.HeaderHandler)
EpochStartRoundCalled func() uint64
}

// RevertStateToBlock -
Expand Down Expand Up @@ -49,6 +51,15 @@ func (e *EpochStartTriggerStub) EpochStartMetaHdrHash() []byte {
return nil
}

// LastCommitedEpochStartHdr -
func (e *EpochStartTriggerStub) LastCommitedEpochStartHdr() (data.HeaderHandler, error) {
if e.LastCommitedEpochStartHdrCalled != nil {
return e.LastCommitedEpochStartHdrCalled()
}

return &block.HeaderV2{}, nil
}

// GetSavedStateKey -
func (e *EpochStartTriggerStub) GetSavedStateKey() []byte {
return []byte("epoch start trigger key")
Expand Down
8 changes: 8 additions & 0 deletions factory/processing/blockProcessorCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (pcf *processComponentsFactory) newShardBlockProcessor(
pcf.config.SmartContractsStorage,
builtInFuncFactory.NFTStorageHandler(),
builtInFuncFactory.ESDTGlobalSettingsHandler(),
epochStartTrigger,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -505,6 +506,7 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor(
pcf.config.SmartContractsStorage,
builtInFuncFactory.NFTStorageHandler(),
builtInFuncFactory.ESDTGlobalSettingsHandler(),
epochStartTrigger,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1064,6 +1066,7 @@ func (pcf *processComponentsFactory) createVMFactoryShard(
configSCStorage config.StorageConfig,
nftStorageHandler vmcommon.SimpleESDTNFTStorageHandler,
globalSettingsHandler vmcommon.ESDTGlobalSettingsHandler,
epochStartTriggerHandler process.EpochStartTriggerHandler,
) (process.VirtualMachinesContainerFactory, error) {
counter, err := counters.NewUsageCounter(esdtTransferParser)
if err != nil {
Expand Down Expand Up @@ -1091,6 +1094,8 @@ func (pcf *processComponentsFactory) createVMFactoryShard(
GasSchedule: pcf.gasSchedule,
Counter: counter,
MissingTrieNodesNotifier: notifier,
EpochStartTrigger: epochStartTriggerHandler,
RoundHandler: pcf.coreData.RoundHandler(),
AdoAdoAdo marked this conversation as resolved.
Show resolved Hide resolved
}

blockChainHookImpl, err := hooks.NewBlockChainHookImpl(argsHook)
Expand Down Expand Up @@ -1121,6 +1126,7 @@ func (pcf *processComponentsFactory) createVMFactoryMeta(
configSCStorage config.StorageConfig,
nftStorageHandler vmcommon.SimpleESDTNFTStorageHandler,
globalSettingsHandler vmcommon.ESDTGlobalSettingsHandler,
epochStartTriggerHandler process.EpochStartTriggerHandler,
) (process.VirtualMachinesContainerFactory, error) {
argsHook := hooks.ArgBlockChainHook{
Accounts: accounts,
Expand All @@ -1143,6 +1149,8 @@ func (pcf *processComponentsFactory) createVMFactoryMeta(
GasSchedule: pcf.gasSchedule,
Counter: counters.NewDisabledCounter(),
MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(),
EpochStartTrigger: epochStartTriggerHandler,
RoundHandler: pcf.coreData.RoundHandler(), // TODO: @laurci - this needs to be replaced when changing the round duration
}

blockChainHookImpl, err := hooks.NewBlockChainHookImpl(argsHook)
Expand Down
4 changes: 2 additions & 2 deletions factory/processing/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ func (pcf *processComponentsFactory) NewBlockProcessor(
}

// CreateAPITransactionEvaluator -
func (pcf *processComponentsFactory) CreateAPITransactionEvaluator(relayedV3TxProcessor process.RelayedTxV3Processor) (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) {
return pcf.createAPITransactionEvaluator(relayedV3TxProcessor)
func (pcf *processComponentsFactory) CreateAPITransactionEvaluator(relayedV3TxProcessor process.RelayedTxV3Processor, epochStartTrigger process.EpochStartTriggerHandler) (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) {
return pcf.createAPITransactionEvaluator(relayedV3TxProcessor, epochStartTrigger)
}
4 changes: 3 additions & 1 deletion factory/processing/processComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type processComponents struct {
sentSignaturesTracker process.SentSignaturesTracker
epochSystemSCProcessor process.EpochStartSystemSCProcessor
relayedTxV3Processor process.RelayedTxV3Processor
epochStartTriggerHanlder epochStart.TriggerHandler
}

// ProcessComponentsFactoryArgs holds the arguments needed to create a process components factory
Expand Down Expand Up @@ -723,7 +724,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) {
return nil, err
}

apiTransactionEvaluator, vmFactoryForTxSimulate, err := pcf.createAPITransactionEvaluator(relayedTxV3Processor)
apiTransactionEvaluator, vmFactoryForTxSimulate, err := pcf.createAPITransactionEvaluator(relayedTxV3Processor, epochStartTrigger)
if err != nil {
return nil, fmt.Errorf("%w when assembling components for the transactions simulator processor", err)
}
Expand Down Expand Up @@ -777,6 +778,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) {
receiptsRepository: receiptsRepository,
sentSignaturesTracker: sentSignaturesTracker,
relayedTxV3Processor: relayedTxV3Processor,
epochStartTriggerHanlder: epochStartTrigger,
}, nil
}

Expand Down
13 changes: 9 additions & 4 deletions factory/processing/txSimulatorProcessComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField"
)

func (pcf *processComponentsFactory) createAPITransactionEvaluator(relayedTxV3Processor process.RelayedTxV3Processor) (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) {
func (pcf *processComponentsFactory) createAPITransactionEvaluator(relayedTxV3Processor process.RelayedTxV3Processor, epochStartTrigger process.EpochStartTriggerHandler) (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) {
simulationAccountsDB, err := transactionEvaluator.NewSimulationAccountsDB(pcf.state.AccountsAdapterAPI())
if err != nil {
return nil, nil, err
Expand All @@ -47,7 +47,7 @@ func (pcf *processComponentsFactory) createAPITransactionEvaluator(relayedTxV3Pr
return nil, nil, err
}

txSimulatorProcessorArgs, vmContainerFactory, txTypeHandler, err := pcf.createArgsTxSimulatorProcessor(simulationAccountsDB, vmOutputCacher, txLogsProcessor, relayedTxV3Processor)
txSimulatorProcessorArgs, vmContainerFactory, txTypeHandler, err := pcf.createArgsTxSimulatorProcessor(simulationAccountsDB, vmOutputCacher, txLogsProcessor, relayedTxV3Processor, epochStartTrigger)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -90,19 +90,21 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessor(
vmOutputCacher storage.Cacher,
txLogsProcessor process.TransactionLogProcessor,
relayedTxV3Processor process.RelayedTxV3Processor,
epochStartTrigger process.EpochStartTriggerHandler,
) (transactionEvaluator.ArgsTxSimulator, process.VirtualMachinesContainerFactory, process.TxTypeHandler, error) {
shardID := pcf.bootstrapComponents.ShardCoordinator().SelfId()
if shardID == core.MetachainShardId {
return pcf.createArgsTxSimulatorProcessorForMeta(accountsAdapter, vmOutputCacher, txLogsProcessor)
return pcf.createArgsTxSimulatorProcessorForMeta(accountsAdapter, vmOutputCacher, txLogsProcessor, epochStartTrigger)
} else {
return pcf.createArgsTxSimulatorProcessorShard(accountsAdapter, vmOutputCacher, txLogsProcessor, relayedTxV3Processor)
return pcf.createArgsTxSimulatorProcessorShard(accountsAdapter, vmOutputCacher, txLogsProcessor, relayedTxV3Processor, epochStartTrigger)
}
}

func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorForMeta(
accountsAdapter state.AccountsAdapter,
vmOutputCacher storage.Cacher,
txLogsProcessor process.TransactionLogProcessor,
epochStartTrigger process.EpochStartTriggerHandler,
) (transactionEvaluator.ArgsTxSimulator, process.VirtualMachinesContainerFactory, process.TxTypeHandler, error) {
args := transactionEvaluator.ArgsTxSimulator{}

Expand Down Expand Up @@ -138,6 +140,7 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorForMeta(
pcf.config.SmartContractsStorageSimulate,
builtInFuncFactory.NFTStorageHandler(),
builtInFuncFactory.ESDTGlobalSettingsHandler(),
epochStartTrigger,
)
if err != nil {
return args, nil, nil, err
Expand Down Expand Up @@ -254,6 +257,7 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard(
vmOutputCacher storage.Cacher,
txLogsProcessor process.TransactionLogProcessor,
relayedTxV3Processor process.RelayedTxV3Processor,
epochStartTrigger process.EpochStartTriggerHandler,
) (transactionEvaluator.ArgsTxSimulator, process.VirtualMachinesContainerFactory, process.TxTypeHandler, error) {
args := transactionEvaluator.ArgsTxSimulator{}

Expand Down Expand Up @@ -304,6 +308,7 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard(
smartContractStorageSimulate,
builtInFuncFactory.NFTStorageHandler(),
builtInFuncFactory.ESDTGlobalSettingsHandler(),
epochStartTrigger,
)
if err != nil {
return args, nil, nil, err
Expand Down
Loading
Loading