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 56 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
56 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
23dab4f
Merge branch 'rc/barnard' into new-blockchain-hooks
laurci Nov 18, 2024
91a906a
fix set header order and add unit tests
laurci Nov 18, 2024
88b8ce5
add logs
laurci Nov 19, 2024
d190c37
don't set current header if epoch start fetch fails
laurci Nov 20, 2024
ea04d0d
don't mask storage error
laurci Nov 21, 2024
50a7149
request epoch start block hash
laurci Dec 2, 2024
39fe24b
request epoch start shard block
laurci Dec 2, 2024
dd9cb7d
request epoch start shard block
laurci Dec 3, 2024
3888988
epoch start shard header syncer
laurci Dec 4, 2024
35fd8f2
epoch start header syncer tests
laurci Dec 11, 2024
c85c294
more test fixing
laurci Dec 11, 2024
ca45571
fix shard check in storage save
laurci Dec 11, 2024
951c0fd
Merge branch 'rc/barnard' into new-blockchain-hooks
laurci Dec 11, 2024
2375301
add more tests and refactors
laurci Dec 12, 2024
77e77f1
Merge branch 'new-blockchain-hooks' of github.com:multiversx/mx-chain…
laurci Dec 12, 2024
f89b8f9
update vm version with new binaries
laurci Dec 22, 2024
6cd3429
use wait group in epoch start shard headers syncer concurrent tests
laurci Dec 22, 2024
114738d
update epoch start trigger tests
laurci Dec 22, 2024
4b564c0
more test coverage, fixes and cleanup
laurci Dec 22, 2024
9ca661f
delegation test fixes
laurci Dec 22, 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
9 changes: 8 additions & 1 deletion epochStart/bootstrap/baseStorageHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,15 @@ func (bsh *baseStorageHandler) saveShardHdrToStorage(hdr data.HeaderHandler) ([]
return nil, err
}

if hdr.IsStartOfEpochBlock() {
err = shardHdrStorage.Put([]byte(core.EpochStartIdentifier(hdr.GetEpoch())), headerBytes)
if err != nil {
return nil, err
}
}

nonceToByteSlice := bsh.uint64Converter.ToByteSlice(hdr.GetNonce())
shardHdrNonceStorage, err := bsh.storageService.GetStorer(dataRetriever.ShardHdrNonceHashDataUnit + dataRetriever.UnitType(hdr.GetShardID()))
shardHdrNonceStorage, err := bsh.storageService.GetStorer(dataRetriever.GetHdrNonceHashDataUnit(hdr.GetShardID()))
if err != nil {
return nil, err
}
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
60 changes: 60 additions & 0 deletions epochStart/bootstrap/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type epochStartBootstrap struct {
dataPool dataRetriever.PoolsHolder
miniBlocksSyncer epochStart.PendingMiniBlocksSyncHandler
headersSyncer epochStart.HeadersByHashSyncer
epochStartShardHeaderSyncer epochStart.PendingEpochStartShardHeaderSyncer
txSyncerForScheduled update.TransactionsSyncHandler
epochStartMetaBlockSyncer epochStart.StartOfEpochMetaSyncer
nodesConfigHandler StartOfEpochNodesConfigHandler
Expand Down Expand Up @@ -618,6 +619,16 @@ func (e *epochStartBootstrap) createSyncers() error {
return err
}

epochStartShardHeaderSyncerArgs := updateSync.ArgsPendingEpochStartShardHeaderSyncer{
HeadersPool: e.dataPool.Headers(),
Marshalizer: e.coreComponentsHolder.InternalMarshalizer(),
RequestHandler: e.requestHandler,
}
e.epochStartShardHeaderSyncer, err = updateSync.NewPendingEpochStartShardHeaderSyncer(epochStartShardHeaderSyncerArgs)
if err != nil {
return err
}

syncTxsArgs := updateSync.ArgsNewTransactionsSyncer{
DataPools: e.dataPool,
Storages: disabled.NewChainStorer(),
Expand Down Expand Up @@ -897,6 +908,46 @@ func (e *epochStartBootstrap) findSelfShardEpochStartData() (data.EpochStartShar
return epochStartData, epochStart.ErrEpochStartDataForShardNotFound
}

func (e *epochStartBootstrap) findPrevEpochLatestFinalizedBlockForShard() (data.EpochStartShardDataHandler, error) {
if check.IfNil(e.prevEpochStartMeta) {
return nil, epochStart.ErrEpochStartDataForShardNotFound
}

epochStartHandler := e.prevEpochStartMeta.GetEpochStartHandler()
if epochStartHandler == nil {
return nil, epochStart.ErrEpochStartDataForShardNotFound
}

lastFinalizedHeaders := epochStartHandler.GetLastFinalizedHeaderHandlers()
for _, hdr := range lastFinalizedHeaders {
if hdr.GetShardID() == e.shardCoordinator.SelfId() {
return hdr, nil
}
}

return nil, epochStart.ErrEpochStartDataForShardNotFound
}

func (e *epochStartBootstrap) syncLatestEpochStartShardBlock(targetEpoch uint32, ctx context.Context) (data.HeaderHandler, []byte, error) {
prevEpochLatestFinalizedBlock, err := e.findPrevEpochLatestFinalizedBlockForShard()
if err != nil || prevEpochLatestFinalizedBlock == nil {
return nil, nil, epochStart.ErrEpochStartDataForShardNotFound
}

e.epochStartShardHeaderSyncer.ClearFields()
err = e.epochStartShardHeaderSyncer.SyncEpochStartShardHeader(e.shardCoordinator.SelfId(), targetEpoch, prevEpochLatestFinalizedBlock.GetNonce(), ctx)
if err != nil {
return nil, nil, err
}

epochStartShardBlock, epochStartShardBlockHash, err := e.epochStartShardHeaderSyncer.GetEpochStartHeader()
if err != nil {
return nil, nil, err
}

return epochStartShardBlock, epochStartShardBlockHash, nil
}

func (e *epochStartBootstrap) requestAndProcessForShard(peerMiniBlocks []*block.MiniBlock) error {
epochStartData, err := e.findSelfShardEpochStartData()
if err != nil {
Expand Down Expand Up @@ -950,6 +1001,15 @@ func (e *epochStartBootstrap) requestAndProcessForShard(peerMiniBlocks []*block.
return epochStart.ErrWrongTypeAssertion
}

ctx, cancel = context.WithTimeout(context.Background(), DefaultTimeToWaitForRequestedData)
laurci marked this conversation as resolved.
Show resolved Hide resolved
epochStartShardBlock, epochStartShardBlockHash, err := e.syncLatestEpochStartShardBlock(epochStartData.GetEpoch(), ctx)
cancel()
if err != nil {
return err
}

e.syncedHeaders[string(epochStartShardBlockHash)] = epochStartShardBlock

dts, err := e.getDataToSync(
epochStartData,
shardNotarizedHeader,
Expand Down
Loading
Loading