mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 12:10:05 +00:00
d916827fb9
* e2e using dynamic configs; runtime bellatrix setup * starts from phase0 but fee recipient eval fails * lower TTD to cross before bellatrix epoch in e2e * fix debug printf * fix it * dynamic ttd and more robust fee_recipient eval * let multiplication set ttd=0 if bellatrix epoch=0 * refactoring fee recipient test after cognit errors * lint * appease deepsource * deep sourcin * gazelle * missed a usage of this when refactoring Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
64 lines
2.6 KiB
Go
64 lines
2.6 KiB
Go
package interop
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/pkg/errors"
|
|
coreState "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
|
|
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
"github.com/prysmaticlabs/prysm/v3/container/trie"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
)
|
|
|
|
// GeneratePreminedGenesisState deterministically given a genesis time and number of validators.
|
|
// If a genesis time of 0 is supplied it is set to the current time.
|
|
func GeneratePreminedGenesisState(ctx context.Context, genesisTime, numValidators uint64, e1d *ethpb.Eth1Data) (*ethpb.BeaconState, []*ethpb.Deposit, error) {
|
|
privKeys, pubKeys, err := DeterministicallyGenerateKeys(0 /*startIndex*/, numValidators)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrapf(err, "could not deterministically generate keys for %d validators", numValidators)
|
|
}
|
|
depositDataItems, depositDataRoots, err := DepositDataFromKeys(privKeys, pubKeys)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "could not generate deposit data from keys")
|
|
}
|
|
return GeneratePreminedGenesisStateFromDepositData(ctx, genesisTime, depositDataItems, depositDataRoots, e1d)
|
|
}
|
|
|
|
// GeneratePreminedGenesisStateFromDepositData creates a genesis state given a list of
|
|
// deposit data items and their corresponding roots.
|
|
func GeneratePreminedGenesisStateFromDepositData(
|
|
ctx context.Context, genesisTime uint64, depositData []*ethpb.Deposit_Data, depositDataRoots [][]byte, e1d *ethpb.Eth1Data,
|
|
) (*ethpb.BeaconState, []*ethpb.Deposit, error) {
|
|
t, err := trie.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "could not generate Merkle trie for deposit proofs")
|
|
}
|
|
deposits, err := GenerateDepositsFromData(depositData, t)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "could not generate deposits from the deposit data provided")
|
|
}
|
|
root, err := t.HashTreeRoot()
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "could not hash tree root of deposit trie")
|
|
}
|
|
if genesisTime == 0 {
|
|
genesisTime = uint64(time.Now().Unix())
|
|
}
|
|
beaconState, err := coreState.PreminedGenesisBeaconState(ctx, deposits, genesisTime, ðpb.Eth1Data{
|
|
DepositRoot: root[:],
|
|
DepositCount: uint64(len(deposits)),
|
|
BlockHash: e1d.BlockHash,
|
|
})
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "could not generate genesis state")
|
|
}
|
|
|
|
pbState, err := statenative.ProtobufBeaconStatePhase0(beaconState.ToProtoUnsafe())
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return pbState, deposits, nil
|
|
}
|