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

new epoch start blockchain hooks #6548

Open
wants to merge 36 commits into
base: rc/barnard
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 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
bc949a7
Merge remote-tracking branch 'origin/rc/barnard' into new-blockchain-…
laurci Oct 21, 2024
98a24b2
fixes after merge
sasurobert Oct 23, 2024
96d4de0
delete files
sasurobert Oct 23, 2024
dc39f02
Merge branch 'spica-to-barnard-23-okt' into new-blockchain-hooks
sasurobert Oct 23, 2024
c27f005
go mod tidy
sasurobert Oct 23, 2024
c47b844
go lint fixes
sasurobert Oct 23, 2024
4a2031b
Merge branch 'spica-to-barnard-23-okt' into new-blockchain-hooks
sasurobert Oct 28, 2024
71dcf66
merges
sasurobert Oct 28, 2024
0ae6ede
Merge branch 'rc/barnard' into new-blockchain-hooks
sasurobert Nov 4, 2024
6af33da
fallback read from storage for epoch start header
laurci Nov 11, 2024
5462659
log.Debug instead of Warn
laurci Nov 12, 2024
cd27078
fix: epoch start block for epoch 0 is the genesis block
laurci Nov 13, 2024
a050424
Merge branch 'rc/barnard' into new-blockchain-hooks
sasurobert Nov 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
9 changes: 9 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 Expand Up @@ -237,6 +242,10 @@
MBufferSetRandom = 6000
MBufferToBigFloat = 2000
MBufferFromBigFloat = 2000
MBufferToSmallIntUnsigned = 10000
MBufferToSmallIntSigned = 10000
MBufferFromSmallIntUnsigned = 10000
MBufferFromSmallIntSigned = 10000

[BigFloatAPICost]
BigFloatNewFromParts = 3000
Expand Down
8 changes: 8 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 Expand Up @@ -237,6 +241,10 @@
MBufferSetRandom = 6000
MBufferToBigFloat = 2000
MBufferFromBigFloat = 2000
MBufferToSmallIntUnsigned = 10000
MBufferToSmallIntSigned = 10000
MBufferFromSmallIntUnsigned = 10000
MBufferFromSmallIntSigned = 10000

[BigFloatAPICost]
BigFloatNewFromParts = 3000
Expand Down
8 changes: 8 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 Expand Up @@ -237,6 +241,10 @@
MBufferSetRandom = 6000
MBufferToBigFloat = 2000
MBufferFromBigFloat = 2000
MBufferToSmallIntUnsigned = 10000
MBufferToSmallIntSigned = 10000
MBufferFromSmallIntUnsigned = 10000
MBufferFromSmallIntSigned = 10000

[BigFloatAPICost]
BigFloatNewFromParts = 3000
Expand Down
8 changes: 8 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 Expand Up @@ -237,6 +241,10 @@
MBufferSetRandom = 6000
MBufferToBigFloat = 2000
MBufferFromBigFloat = 2000
MBufferToSmallIntUnsigned = 10000
MBufferToSmallIntSigned = 10000
MBufferFromSmallIntUnsigned = 10000
MBufferFromSmallIntSigned = 10000

[BigFloatAPICost]
BigFloatNewFromParts = 3000
Expand Down
8 changes: 8 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 Expand Up @@ -237,6 +241,10 @@
MBufferSetRandom = 6000
MBufferToBigFloat = 2000
MBufferFromBigFloat = 2000
MBufferToSmallIntUnsigned = 10000
MBufferToSmallIntSigned = 10000
MBufferFromSmallIntUnsigned = 10000
MBufferFromSmallIntSigned = 10000

[BigFloatAPICost]
BigFloatNewFromParts = 3000
Expand Down
8 changes: 8 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 Expand Up @@ -237,6 +241,10 @@
MBufferSetRandom = 6000
MBufferToBigFloat = 2000
MBufferFromBigFloat = 2000
MBufferToSmallIntUnsigned = 10000
MBufferToSmallIntSigned = 10000
MBufferFromSmallIntUnsigned = 10000
MBufferFromSmallIntSigned = 10000

[BigFloatAPICost]
BigFloatNewFromParts = 3000
Expand Down
8 changes: 8 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 Expand Up @@ -238,6 +242,10 @@
MBufferSetRandom = 6000
MBufferToBigFloat = 2000
MBufferFromBigFloat = 2000
MBufferToSmallIntUnsigned = 10000
MBufferToSmallIntSigned = 10000
MBufferFromSmallIntUnsigned = 10000
MBufferFromSmallIntSigned = 10000

[BigFloatAPICost]
BigFloatNewFromParts = 3000
Expand Down
8 changes: 8 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 Expand Up @@ -238,6 +242,10 @@
MBufferSetRandom = 6000
MBufferToBigFloat = 2000
MBufferFromBigFloat = 2000
MBufferToSmallIntUnsigned = 10000
MBufferToSmallIntSigned = 10000
MBufferFromSmallIntUnsigned = 10000
MBufferFromSmallIntSigned = 10000

[BigFloatAPICost]
BigFloatNewFromParts = 3000
Expand Down
11 changes: 11 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,16 @@ func (e *epochStartTrigger) EpochStartMetaHdrHash() []byte {
return nil
}

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

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

// GetSavedStateKey -
func (e *epochStartTrigger) GetSavedStateKey() []byte {
return nil
Expand Down
2 changes: 2 additions & 0 deletions epochStart/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type TriggerHandler interface {
Update(round uint64, nonce uint64)
EpochStartRound() uint64
EpochStartMetaHdrHash() []byte
LastCommitedEpochStartHdr() (data.HeaderHandler, error)
GetEpochStartHdrFromStorage(epoch uint32) (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
36 changes: 35 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,40 @@ func (t *trigger) EpochStartMetaHdrHash() []byte {
return t.epochStartMetaHash
}

// LastCommitedEpochStartHdr returns the header of the epoch start block
func (t *trigger) LastCommitedEpochStartHdr() (data.HeaderHandler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add unit tests

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)
}

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

epochStartIdentifier := core.EpochStartIdentifier(epoch)
epochStartMetaBuff, err := t.metaHeaderStorage.SearchFirst([]byte(epochStartIdentifier))
if err != nil {
return nil, err
}

metaHdr := &block.MetaBlock{}
err = t.marshaller.Unmarshal(metaHdr, epochStartMetaBuff)
if err != nil {
return nil, err
}

return metaHdr, nil
}

// GetSavedStateKey returns the last saved trigger state key
func (t *trigger) GetSavedStateKey() []byte {
return t.triggerStateKey
Expand Down
27 changes: 26 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,31 @@ func (t *trigger) EpochStartMetaHdrHash() []byte {
return t.epochMetaBlockHash
}

// LastCommitedEpochStartHdr returns the epoch start header
func (t *trigger) LastCommitedEpochStartHdr() (data.HeaderHandler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add unit tests.

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)
}

// GetEpochStartHdrFromStorage returns the epoch start header from storage
func (t *trigger) GetEpochStartHdrFromStorage(epoch uint32) (data.HeaderHandler, error) {
epochStartIdentifier := core.EpochStartIdentifier(epoch)
shardHdrBuff, err := t.shardHdrStorage.SearchFirst([]byte(epochStartIdentifier))
if err != nil {
return nil, err
}

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

// 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 @@ -413,6 +413,8 @@ func createScQueryElement(
MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(),
Accounts: accountsAdapterApi,
BlockChain: apiBlockchain,
EpochStartTrigger: args.processComponents.EpochStartTrigger(),
RoundHandler: args.processComponents.RoundHandler(),
}

var vmFactory process.VirtualMachinesContainerFactory
Expand Down
3 changes: 2 additions & 1 deletion factory/consensus/consensusComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-crypto-go"
crypto "github.com/multiversx/mx-chain-crypto-go"
"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 @@ -141,6 +141,7 @@ func createMockConsensusComponentsFactoryArgs() consensusComp.ConsensusComponent
HeaderIntegrVerif: &mock.HeaderIntegrityVerifierStub{},
FallbackHdrValidator: &testscommon.FallBackHeaderValidatorStub{},
SentSignaturesTrackerInternal: &testscommon.SentSignatureTrackerStub{},
BlockchainHookField: &testscommon.BlockChainHookStub{},
},
StateComponents: &factoryMocks.StateComponentsMock{
StorageManagers: map[string]common.StorageManager{
Expand Down
1 change: 1 addition & 0 deletions factory/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ type ProcessComponentsHolder interface {
ReceiptsRepository() ReceiptsRepository
SentSignaturesTracker() process.SentSignaturesTracker
EpochSystemSCProcessor() process.EpochStartSystemSCProcessor
BlockchainHook() process.BlockChainHookWithAccountsAdapter
IsInterfaceNil() bool
}

Expand Down
Loading
Loading