mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
QSP-Docs All Documentation Improvements from Quantstamp Audit Report (#6367)
* docs improvements so far * all misc docs items * finalized * Merge branch 'master' into qsp-docs * fix broken test * Merge branch 'master' into qsp-docs
This commit is contained in:
@@ -133,7 +133,7 @@ func (s *Service) HeadRoot(ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
// HeadBlock returns the head block of the chain.
|
||||
// If the head state is nil from service struct,
|
||||
// If the head is nil from service struct,
|
||||
// it will attempt to get the head block from DB.
|
||||
func (s *Service) HeadBlock(ctx context.Context) (*ethpb.SignedBeaconBlock, error) {
|
||||
if s.hasHeadState() {
|
||||
@@ -144,7 +144,7 @@ func (s *Service) HeadBlock(ctx context.Context) (*ethpb.SignedBeaconBlock, erro
|
||||
}
|
||||
|
||||
// HeadState returns the head state of the chain.
|
||||
// If the head state is nil from service struct,
|
||||
// If the head is nil from service struct,
|
||||
// it will attempt to get the head state from DB.
|
||||
func (s *Service) HeadState(ctx context.Context) (*state.BeaconState, error) {
|
||||
if s.hasHeadState() {
|
||||
|
||||
@@ -26,8 +26,8 @@ type head struct {
|
||||
state *state.BeaconState // current head state.
|
||||
}
|
||||
|
||||
// This gets head from the fork choice service and saves head related items
|
||||
// (ie root, block, state) to the local service cache.
|
||||
// Determined the head from the fork choice service and saves its new data
|
||||
// (head root, head block, and head state) to the local service cache.
|
||||
func (s *Service) updateHead(ctx context.Context, balances []uint64) error {
|
||||
ctx, span := trace.StartSpan(ctx, "blockchain.updateHead")
|
||||
defer span.End()
|
||||
@@ -128,7 +128,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
|
||||
}
|
||||
|
||||
// This gets called to update canonical root mapping. It does not save head block
|
||||
// root in DB. With the inception of inital-sync-cache-state flag, it uses finalized
|
||||
// root in DB. With the inception of initial-sync-cache-state flag, it uses finalized
|
||||
// check point as anchors to resume sync therefore head is no longer needed to be saved on per slot basis.
|
||||
func (s *Service) saveHeadNoDB(ctx context.Context, b *ethpb.SignedBeaconBlock, r [32]byte) error {
|
||||
if b == nil || b.Block == nil {
|
||||
|
||||
@@ -78,11 +78,11 @@ var (
|
||||
})
|
||||
totalEligibleBalances = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "total_eligible_balances",
|
||||
Help: "The total amount of ether, in gwei, that has been used in voting attestation target of previous epoch",
|
||||
Help: "The total amount of ether, in gwei, that is eligible for voting of previous epoch",
|
||||
})
|
||||
totalVotedTargetBalances = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "total_voted_target_balances",
|
||||
Help: "The total amount of ether, in gwei, that is eligible for voting of previous epoch",
|
||||
Help: "The total amount of ether, in gwei, that has been used in voting attestation target of previous epoch",
|
||||
})
|
||||
reorgCount = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "beacon_reorg_total",
|
||||
|
||||
@@ -121,7 +121,7 @@ func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) ([]ui
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Use the target state to to validate attestation and calculate the committees.
|
||||
// Use the target state to validate attestation and calculate the committees.
|
||||
indexedAtt, err := s.verifyAttestation(ctx, baseState, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -41,7 +41,7 @@ var initialSyncBlockCacheSize = 2 * params.BeaconConfig().SlotsPerEpoch
|
||||
// store.finalized_checkpoint.root
|
||||
// )
|
||||
// # Check that block is later than the finalized epoch slot
|
||||
// assert block.slot > compute_start_slot_of_epoch(store.finalized_checkpoint.epoch)
|
||||
// assert block.slot > compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)
|
||||
// # Check the block is valid and compute the post-state
|
||||
// state = state_transition(pre_state, block)
|
||||
// # Add new state for this block to the store
|
||||
|
||||
@@ -26,7 +26,7 @@ type AttestationReceiver interface {
|
||||
AttestationPreState(ctx context.Context, att *ethpb.Attestation) (*state.BeaconState, error)
|
||||
}
|
||||
|
||||
// ReceiveAttestationNoPubsub is a function that defines the operations that are preformed on
|
||||
// ReceiveAttestationNoPubsub is a function that defines the operations that are performed on
|
||||
// attestation that is received from regular sync. The operations consist of:
|
||||
// 1. Validate attestation, update validator's latest vote
|
||||
// 2. Apply fork choice to the processed attestation
|
||||
|
||||
@@ -26,7 +26,7 @@ type BlockReceiver interface {
|
||||
HasInitSyncBlock(root [32]byte) bool
|
||||
}
|
||||
|
||||
// ReceiveBlock is a function that defines the operations that are preformed on
|
||||
// ReceiveBlock is a function that defines the operations that are performed on
|
||||
// blocks that is received from rpc service. The operations consists of:
|
||||
// 1. Gossip block to other peers
|
||||
// 2. Validate block, apply state transition and update check points
|
||||
@@ -57,7 +57,7 @@ func (s *Service) ReceiveBlock(ctx context.Context, block *ethpb.SignedBeaconBlo
|
||||
}
|
||||
|
||||
// ReceiveBlockNoPubsub is a function that defines the the operations (minus pubsub)
|
||||
// that are preformed on blocks that is received from regular sync service. The operations consists of:
|
||||
// that are performed on blocks that is received from regular sync service. The operations consists of:
|
||||
// 1. Validate block, apply state transition and update check points
|
||||
// 2. Apply fork choice to the processed block
|
||||
// 3. Save latest head info
|
||||
|
||||
@@ -561,8 +561,7 @@ func slashableAttesterIndices(slashing *ethpb.AttesterSlashing) []uint64 {
|
||||
}
|
||||
|
||||
// ProcessAttestations applies processing operations to a block's inner attestation
|
||||
// records. This function returns a list of pending attestations which can then be
|
||||
// appended to the BeaconState's latest attestations.
|
||||
// records.
|
||||
func ProcessAttestations(
|
||||
ctx context.Context,
|
||||
beaconState *stateTrie.BeaconState,
|
||||
@@ -974,7 +973,7 @@ func ProcessPreGenesisDeposit(
|
||||
// assert is_valid_merkle_branch(
|
||||
// leaf=hash_tree_root(deposit.data),
|
||||
// branch=deposit.proof,
|
||||
// depth=DEPOSIT_CONTRACT_TREE_DEPTH + 1, # Add 1 for the `List` length mix-in
|
||||
// depth=DEPOSIT_CONTRACT_TREE_DEPTH + 1, # Add 1 for the List length mix-in
|
||||
// index=state.eth1_deposit_index,
|
||||
// root=state.eth1_data.deposit_root,
|
||||
// )
|
||||
@@ -986,23 +985,19 @@ func ProcessPreGenesisDeposit(
|
||||
// amount = deposit.data.amount
|
||||
// validator_pubkeys = [v.pubkey for v in state.validators]
|
||||
// if pubkey not in validator_pubkeys:
|
||||
// # Verify the deposit signature (proof of possession) for new validators.
|
||||
// # Note: The deposit contract does not check signatures.
|
||||
// # Note: Deposits are valid across forks, thus the deposit domain is retrieved directly from `compute_domain`.
|
||||
// domain = compute_domain(DOMAIN_DEPOSIT)
|
||||
// if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, domain):
|
||||
// # Verify the deposit signature (proof of possession) which is not checked by the deposit contract
|
||||
// deposit_message = DepositMessage(
|
||||
// pubkey=deposit.data.pubkey,
|
||||
// withdrawal_credentials=deposit.data.withdrawal_credentials,
|
||||
// amount=deposit.data.amount,
|
||||
// )
|
||||
// domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks
|
||||
// signing_root = compute_signing_root(deposit_message, domain)
|
||||
// if not bls.Verify(pubkey, signing_root, deposit.data.signature):
|
||||
// return
|
||||
//
|
||||
// # Add validator and balance entries
|
||||
// state.validators.append(Validator(
|
||||
// pubkey=pubkey,
|
||||
// withdrawal_credentials=deposit.data.withdrawal_credentials,
|
||||
// activation_eligibility_epoch=FAR_FUTURE_EPOCH,
|
||||
// activation_epoch=FAR_FUTURE_EPOCH,
|
||||
// exit_epoch=FAR_FUTURE_EPOCH,
|
||||
// withdrawable_epoch=FAR_FUTURE_EPOCH,
|
||||
// effective_balance=min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE),
|
||||
// ))
|
||||
// state.validators.append(get_validator_from_deposit(state, deposit))
|
||||
// state.balances.append(amount)
|
||||
// else:
|
||||
// # Increase balance by deposit amount
|
||||
|
||||
@@ -209,6 +209,7 @@ func ProcessSlashings(state *stateTrie.BeaconState) (*stateTrie.BeaconState, err
|
||||
// balance + DOWNWARD_THRESHOLD < validator.effective_balance
|
||||
// or validator.effective_balance + UPWARD_THRESHOLD < balance
|
||||
// ):
|
||||
// validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
|
||||
// index_epoch = Epoch(next_epoch + ACTIVATION_EXIT_DELAY)
|
||||
// index_root_position = index_epoch % EPOCHS_PER_HISTORICAL_VECTOR
|
||||
// indices_list = List[ValidatorIndex, VALIDATOR_REGISTRY_LIMIT](get_active_validator_indices(state, index_epoch))
|
||||
|
||||
@@ -10,6 +10,44 @@ import (
|
||||
// ProcessJustificationAndFinalizationPreCompute processes justification and finalization during
|
||||
// epoch processing. This is where a beacon node can justify and finalize a new epoch.
|
||||
// Note: this is an optimized version by passing in precomputed total and attesting balances.
|
||||
// def process_justification_and_finalization(state: BeaconState) -> None:
|
||||
// if get_current_epoch(state) <= GENESIS_EPOCH + 1:
|
||||
// return
|
||||
//
|
||||
// previous_epoch = get_previous_epoch(state)
|
||||
// current_epoch = get_current_epoch(state)
|
||||
// old_previous_justified_checkpoint = state.previous_justified_checkpoint
|
||||
// old_current_justified_checkpoint = state.current_justified_checkpoint
|
||||
//
|
||||
// # Process justifications
|
||||
// state.previous_justified_checkpoint = state.current_justified_checkpoint
|
||||
// state.justification_bits[1:] = state.justification_bits[:-1]
|
||||
// state.justification_bits[0] = 0b0
|
||||
// matching_target_attestations = get_matching_target_attestations(state, previous_epoch) # Previous epoch
|
||||
// if get_attesting_balance(state, matching_target_attestations) * 3 >= get_total_active_balance(state) * 2:
|
||||
// state.current_justified_checkpoint = Checkpoint(epoch=previous_epoch,
|
||||
// root=get_block_root(state, previous_epoch))
|
||||
// state.justification_bits[1] = 0b1
|
||||
// matching_target_attestations = get_matching_target_attestations(state, current_epoch) # Current epoch
|
||||
// if get_attesting_balance(state, matching_target_attestations) * 3 >= get_total_active_balance(state) * 2:
|
||||
// state.current_justified_checkpoint = Checkpoint(epoch=current_epoch,
|
||||
// root=get_block_root(state, current_epoch))
|
||||
// state.justification_bits[0] = 0b1
|
||||
//
|
||||
// # Process finalizations
|
||||
// bits = state.justification_bits
|
||||
// # The 2nd/3rd/4th most recent epochs are justified, the 2nd using the 4th as source
|
||||
// if all(bits[1:4]) and old_previous_justified_checkpoint.epoch + 3 == current_epoch:
|
||||
// state.finalized_checkpoint = old_previous_justified_checkpoint
|
||||
// # The 2nd/3rd most recent epochs are justified, the 2nd using the 3rd as source
|
||||
// if all(bits[1:3]) and old_previous_justified_checkpoint.epoch + 2 == current_epoch:
|
||||
// state.finalized_checkpoint = old_previous_justified_checkpoint
|
||||
// # The 1st/2nd/3rd most recent epochs are justified, the 1st using the 3rd as source
|
||||
// if all(bits[0:3]) and old_current_justified_checkpoint.epoch + 2 == current_epoch:
|
||||
// state.finalized_checkpoint = old_current_justified_checkpoint
|
||||
// # The 1st/2nd most recent epochs are justified, the 1st using the 2nd as source
|
||||
// if all(bits[0:2]) and old_current_justified_checkpoint.epoch + 1 == current_epoch:
|
||||
// state.finalized_checkpoint = old_current_justified_checkpoint
|
||||
func ProcessJustificationAndFinalizationPreCompute(state *stateTrie.BeaconState, pBal *Balance) (*stateTrie.BeaconState, error) {
|
||||
if state.Slot() <= helpers.StartSlot(2) {
|
||||
return state, nil
|
||||
|
||||
@@ -30,7 +30,7 @@ func BlockRootAtSlot(state *stateTrie.BeaconState, slot uint64) ([]byte, error)
|
||||
// """
|
||||
// Return the block root at the start of a recent ``epoch``.
|
||||
// """
|
||||
// return get_block_root_at_slot(state, compute_start_slot_of_epoch(epoch))
|
||||
// return get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch))
|
||||
func BlockRoot(state *stateTrie.BeaconState, epoch uint64) ([]byte, error) {
|
||||
return BlockRootAtSlot(state, StartSlot(epoch))
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func CurrentEpoch(state *stateTrie.BeaconState) uint64 {
|
||||
}
|
||||
|
||||
// PrevEpoch returns the previous epoch number calculated from
|
||||
// the slot number stored in beacon state. It alswo checks for
|
||||
// the slot number stored in beacon state. It also checks for
|
||||
// underflow condition.
|
||||
//
|
||||
// Spec pseudocode definition:
|
||||
@@ -54,7 +54,7 @@ func PrevEpoch(state *stateTrie.BeaconState) uint64 {
|
||||
return currentEpoch - 1
|
||||
}
|
||||
|
||||
// NextEpoch returns the next epoch number calculated form
|
||||
// NextEpoch returns the next epoch number calculated from
|
||||
// the slot number stored in beacon state.
|
||||
func NextEpoch(state *stateTrie.BeaconState) uint64 {
|
||||
return SlotToEpoch(state.Slot()) + 1
|
||||
@@ -64,7 +64,7 @@ func NextEpoch(state *stateTrie.BeaconState) uint64 {
|
||||
// current epoch.
|
||||
//
|
||||
// Spec pseudocode definition:
|
||||
// def compute_start_slot_of_epoch(epoch: Epoch) -> Slot:
|
||||
// def compute_start_slot_at_epoch(epoch: Epoch) -> Slot:
|
||||
// """
|
||||
// Return the start slot of ``epoch``.
|
||||
// """
|
||||
|
||||
@@ -233,7 +233,7 @@ func ProcessSlot(ctx context.Context, state *stateTrie.BeaconState) (*stateTrie.
|
||||
return state, nil
|
||||
}
|
||||
|
||||
// ProcessSlots process through skip skips and apply epoch transition when it's needed
|
||||
// ProcessSlots process through skip slots and apply epoch transition when it's needed
|
||||
//
|
||||
// Spec pseudocode definition:
|
||||
// def process_slots(state: BeaconState, slot: Slot) -> None:
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
)
|
||||
|
||||
// ReadOnlyDatabase -- See github.com/prysmaticlabs/prysm/beacon-chain/db.ReadOnlyDatabase
|
||||
// ReadOnlyDatabase defines a struct which only has read access to database methods.
|
||||
type ReadOnlyDatabase interface {
|
||||
// Attestation related methods.
|
||||
AttestationsByDataRoot(ctx context.Context, attDataRoot [32]byte) ([]*eth.Attestation, error)
|
||||
@@ -65,7 +65,7 @@ type ReadOnlyDatabase interface {
|
||||
PowchainData(ctx context.Context) (*db.ETH1ChainData, error)
|
||||
}
|
||||
|
||||
// NoHeadAccessDatabase -- See github.com/prysmaticlabs/prysm/beacon-chain/db.NoHeadAccessDatabase
|
||||
// NoHeadAccessDatabase defines a struct without access to chain head data.
|
||||
type NoHeadAccessDatabase interface {
|
||||
ReadOnlyDatabase
|
||||
|
||||
@@ -111,7 +111,7 @@ type NoHeadAccessDatabase interface {
|
||||
SavePowchainData(ctx context.Context, data *db.ETH1ChainData) error
|
||||
}
|
||||
|
||||
// HeadAccessDatabase -- See github.com/prysmaticlabs/prysm/beacon-chain/db.HeadAccessDatabase
|
||||
// HeadAccessDatabase defines a struct with access to reading chain head data.
|
||||
type HeadAccessDatabase interface {
|
||||
NoHeadAccessDatabase
|
||||
|
||||
@@ -122,7 +122,7 @@ type HeadAccessDatabase interface {
|
||||
HeadState(ctx context.Context) (*state.BeaconState, error)
|
||||
}
|
||||
|
||||
// Database -- See github.com/prysmaticlabs/prysm/beacon-chain/db.Database
|
||||
// Database interface with full access.
|
||||
type Database interface {
|
||||
io.Closer
|
||||
HeadAccessDatabase
|
||||
|
||||
@@ -495,7 +495,7 @@ func getBlockRootsByFilter(ctx context.Context, tx *bolt.Tx, f *filters.QueryFil
|
||||
|
||||
// fetchBlockRootsBySlotRange looks into a boltDB bucket and performs a binary search
|
||||
// range scan using sorted left-padded byte keys using a start slot and an end slot.
|
||||
// If both the start and end slot are the same, and are 0, the function returns nil.
|
||||
// However, if step is one, the implemented logic won’t skip half of the slots in the range.
|
||||
func fetchBlockRootsBySlotRange(
|
||||
ctx context.Context,
|
||||
bkt *bolt.Bucket,
|
||||
@@ -590,8 +590,7 @@ func createBlockIndicesFromBlock(ctx context.Context, block *ethpb.BeaconBlock)
|
||||
}
|
||||
|
||||
// createBlockFiltersFromIndices takes in filter criteria and returns
|
||||
// a list of of byte keys used to retrieve the values stored
|
||||
// for the indices from the DB.
|
||||
// a map with a single key-value pair: "block-parent-root-indices” -> parentRoot (array of bytes).
|
||||
//
|
||||
// For blocks, these are list of signing roots of block
|
||||
// objects. If a certain filter criterion does not apply to
|
||||
|
||||
@@ -180,7 +180,7 @@ func (e SszNetworkEncoder) DecodeWithMaxLength(r io.Reader, to interface{}, maxS
|
||||
defer bufReaderPool.Put(r)
|
||||
}
|
||||
if msgLen > maxSize {
|
||||
return fmt.Errorf("size of decoded message is %d which is larger than the provided max limit of %d", msgLen, maxSize)
|
||||
return fmt.Errorf("remaining bytes %d goes over the provided max limit of %d", msgLen, maxSize)
|
||||
}
|
||||
b := make([]byte, e.MaxLength(int(msgLen)))
|
||||
numOfBytes, err := r.Read(b)
|
||||
|
||||
@@ -117,7 +117,7 @@ func TestSszNetworkEncoder_DecodeWithMaxLength(t *testing.T) {
|
||||
}
|
||||
decoded := &testpb.TestSimpleMessage{}
|
||||
err = e.DecodeWithMaxLength(buf, decoded, maxLength)
|
||||
wanted := fmt.Sprintf("which is larger than the provided max limit of %d", maxLength)
|
||||
wanted := fmt.Sprintf("goes over the provided max limit of %d", maxLength)
|
||||
if err == nil {
|
||||
t.Fatalf("wanted this error %s but got nothing", wanted)
|
||||
}
|
||||
|
||||
@@ -354,8 +354,8 @@ func (s *Service) MetadataSeq() uint64 {
|
||||
}
|
||||
|
||||
// RefreshENR uses an epoch to refresh the enr entry for our node
|
||||
// with the tracked committee id's for the epoch, allowing our node
|
||||
// to be dynamically discoverable by others given our tracked committee id's.
|
||||
// with the tracked committee ids for the epoch, allowing our node
|
||||
// to be dynamically discoverable by others given our tracked committee ids.
|
||||
func (s *Service) RefreshENR() {
|
||||
// return early if discv5 isnt running
|
||||
if s.dv5Listener == nil {
|
||||
|
||||
@@ -11,6 +11,8 @@ var attestationSubnetCount = params.BeaconNetworkConfig().AttestationSubnetCount
|
||||
|
||||
var attSubnetEnrKey = params.BeaconNetworkConfig().AttSubnetKey
|
||||
|
||||
// Initializes a bitvector of attestation subnets beacon nodes is subscribed to
|
||||
// and creates a new ENR entry with its default value.
|
||||
func intializeAttSubnets(node *enode.LocalNode) *enode.LocalNode {
|
||||
bitV := bitfield.NewBitvector64()
|
||||
entry := enr.WithEntry(attSubnetEnrKey, bitV.Bytes())
|
||||
@@ -18,6 +20,8 @@ func intializeAttSubnets(node *enode.LocalNode) *enode.LocalNode {
|
||||
return node
|
||||
}
|
||||
|
||||
// Reads the attestation subnets entry from a node's ENR and determines
|
||||
// the committee indices of the attestation subnets the node is subscribed to.
|
||||
func retrieveAttSubnets(record *enr.Record) ([]uint64, error) {
|
||||
bitV, err := retrieveBitvector(record)
|
||||
if err != nil {
|
||||
@@ -32,6 +36,8 @@ func retrieveAttSubnets(record *enr.Record) ([]uint64, error) {
|
||||
return committeeIdxs, nil
|
||||
}
|
||||
|
||||
// Parses the attestation subnets ENR entry in a node and extracts its value
|
||||
// as a bitvector for further manipulation.
|
||||
func retrieveBitvector(record *enr.Record) (bitfield.Bitvector64, error) {
|
||||
bitV := bitfield.NewBitvector64()
|
||||
entry := enr.WithEntry(attSubnetEnrKey, &bitV)
|
||||
|
||||
@@ -53,6 +53,8 @@ func convertToInterfacePubkey(pubkey *ecdsa.PublicKey) crypto.PubKey {
|
||||
return typeAssertedKey
|
||||
}
|
||||
|
||||
// Determines a private key for p2p networking from the p2p service's
|
||||
// configuration struct. If no key is found, it generates a new one.
|
||||
func privKey(cfg *Config) (*ecdsa.PrivateKey, error) {
|
||||
defaultKeyPath := path.Join(cfg.DataDir, keyPath)
|
||||
privateKeyPath := cfg.PrivateKey
|
||||
@@ -86,6 +88,7 @@ func privKey(cfg *Config) (*ecdsa.PrivateKey, error) {
|
||||
return retrievePrivKeyFromFile(privateKeyPath)
|
||||
}
|
||||
|
||||
// Retrieves a p2p networking private key from a file path.
|
||||
func retrievePrivKeyFromFile(path string) (*ecdsa.PrivateKey, error) {
|
||||
src, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
@@ -104,6 +107,8 @@ func retrievePrivKeyFromFile(path string) (*ecdsa.PrivateKey, error) {
|
||||
return convertFromInterfacePrivKey(unmarshalledKey), nil
|
||||
}
|
||||
|
||||
// Retrieves node p2p metadata from a set of configuration values
|
||||
// from the p2p service.
|
||||
func metaDataFromConfig(cfg *Config) (*pbp2p.MetaData, error) {
|
||||
defaultKeyPath := path.Join(cfg.DataDir, metaDataPath)
|
||||
metaDataPath := cfg.MetaDataDir
|
||||
@@ -142,6 +147,7 @@ func metaDataFromConfig(cfg *Config) (*pbp2p.MetaData, error) {
|
||||
return metaData, nil
|
||||
}
|
||||
|
||||
// Retrieves an external ipv4 address and converts into a libp2p formatted value.
|
||||
func ipAddr() net.IP {
|
||||
ip, err := iputils.ExternalIPv4()
|
||||
if err != nil {
|
||||
|
||||
@@ -76,7 +76,7 @@ func (b *BeaconState) SetLatestBlockHeader(val *ethpb.BeaconBlockHeader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetBlockRoots for the beacon state. This PR updates the entire
|
||||
// SetBlockRoots for the beacon state. Updates the entire
|
||||
// list to a new value by overwriting the previous one.
|
||||
func (b *BeaconState) SetBlockRoots(val [][]byte) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -93,7 +93,7 @@ func (b *BeaconState) SetBlockRoots(val [][]byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateBlockRootAtIndex for the beacon state. This PR updates the randao mixes
|
||||
// UpdateBlockRootAtIndex for the beacon state. Updates the block root
|
||||
// at a specific index to a new value.
|
||||
func (b *BeaconState) UpdateBlockRootAtIndex(idx uint64, blockRoot [32]byte) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -131,8 +131,8 @@ func (b *BeaconState) UpdateBlockRootAtIndex(idx uint64, blockRoot [32]byte) err
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetStateRoots for the beacon state. This PR updates the entire
|
||||
// to a new value by overwriting the previous one.
|
||||
// SetStateRoots for the beacon state. Updates the state roots
|
||||
// to a new value by overwriting the previous value.
|
||||
func (b *BeaconState) SetStateRoots(val [][]byte) error {
|
||||
if !b.HasInnerState() {
|
||||
return ErrNilInnerState
|
||||
@@ -149,7 +149,7 @@ func (b *BeaconState) SetStateRoots(val [][]byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateStateRootAtIndex for the beacon state. This PR updates the randao mixes
|
||||
// UpdateStateRootAtIndex for the beacon state. Updates the state root
|
||||
// at a specific index to a new value.
|
||||
func (b *BeaconState) UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -188,7 +188,7 @@ func (b *BeaconState) UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) err
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetHistoricalRoots for the beacon state. This PR updates the entire
|
||||
// SetHistoricalRoots for the beacon state. Updates the entire
|
||||
// list to a new value by overwriting the previous one.
|
||||
func (b *BeaconState) SetHistoricalRoots(val [][]byte) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -218,7 +218,7 @@ func (b *BeaconState) SetEth1Data(val *ethpb.Eth1Data) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetEth1DataVotes for the beacon state. This PR updates the entire
|
||||
// SetEth1DataVotes for the beacon state. Updates the entire
|
||||
// list to a new value by overwriting the previous one.
|
||||
func (b *BeaconState) SetEth1DataVotes(val []*ethpb.Eth1Data) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -236,7 +236,7 @@ func (b *BeaconState) SetEth1DataVotes(val []*ethpb.Eth1Data) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AppendEth1DataVotes for the beacon state. This PR appends the new value
|
||||
// AppendEth1DataVotes for the beacon state. Appends the new value
|
||||
// to the the end of list.
|
||||
func (b *BeaconState) AppendEth1DataVotes(val *ethpb.Eth1Data) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -278,7 +278,7 @@ func (b *BeaconState) SetEth1DepositIndex(val uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetValidators for the beacon state. This PR updates the entire
|
||||
// SetValidators for the beacon state. Updates the entire
|
||||
// to a new value by overwriting the previous one.
|
||||
func (b *BeaconState) SetValidators(val []*ethpb.Validator) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -333,7 +333,7 @@ func (b *BeaconState) ApplyToEveryValidator(f func(idx int, val *ethpb.Validator
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateValidatorAtIndex for the beacon state. This PR updates the randao mixes
|
||||
// UpdateValidatorAtIndex for the beacon state. Updates the validator
|
||||
// at a specific index to a new value.
|
||||
func (b *BeaconState) UpdateValidatorAtIndex(idx uint64, val *ethpb.Validator) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -378,7 +378,7 @@ func (b *BeaconState) SetValidatorIndexByPubkey(pubKey [48]byte, validatorIdx ui
|
||||
b.valIdxMap = m
|
||||
}
|
||||
|
||||
// SetBalances for the beacon state. This PR updates the entire
|
||||
// SetBalances for the beacon state. Updates the entire
|
||||
// list to a new value by overwriting the previous one.
|
||||
func (b *BeaconState) SetBalances(val []uint64) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -423,8 +423,8 @@ func (b *BeaconState) UpdateBalancesAtIndex(idx uint64, val uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetRandaoMixes for the beacon state. This PR updates the entire
|
||||
// list to a new value by overwriting the previous one.
|
||||
// SetRandaoMixes for the beacon state. Updates the entire
|
||||
// randao mixes to a new value by overwriting the previous one.
|
||||
func (b *BeaconState) SetRandaoMixes(val [][]byte) error {
|
||||
if !b.HasInnerState() {
|
||||
return ErrNilInnerState
|
||||
@@ -441,7 +441,7 @@ func (b *BeaconState) SetRandaoMixes(val [][]byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateRandaoMixesAtIndex for the beacon state. This PR updates the randao mixes
|
||||
// UpdateRandaoMixesAtIndex for the beacon state. Updates the randao mixes
|
||||
// at a specific index to a new value.
|
||||
func (b *BeaconState) UpdateRandaoMixesAtIndex(idx uint64, val []byte) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -476,7 +476,7 @@ func (b *BeaconState) UpdateRandaoMixesAtIndex(idx uint64, val []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetSlashings for the beacon state. This PR updates the entire
|
||||
// SetSlashings for the beacon state. Updates the entire
|
||||
// list to a new value by overwriting the previous one.
|
||||
func (b *BeaconState) SetSlashings(val []uint64) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -493,7 +493,7 @@ func (b *BeaconState) SetSlashings(val []uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateSlashingsAtIndex for the beacon state. This PR updates the randao mixes
|
||||
// UpdateSlashingsAtIndex for the beacon state. Updates the slashings
|
||||
// at a specific index to a new value.
|
||||
func (b *BeaconState) UpdateSlashingsAtIndex(idx uint64, val uint64) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -523,7 +523,7 @@ func (b *BeaconState) UpdateSlashingsAtIndex(idx uint64, val uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetPreviousEpochAttestations for the beacon state. This PR updates the entire
|
||||
// SetPreviousEpochAttestations for the beacon state. Updates the entire
|
||||
// list to a new value by overwriting the previous one.
|
||||
func (b *BeaconState) SetPreviousEpochAttestations(val []*pbp2p.PendingAttestation) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -541,7 +541,7 @@ func (b *BeaconState) SetPreviousEpochAttestations(val []*pbp2p.PendingAttestati
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetCurrentEpochAttestations for the beacon state. This PR updates the entire
|
||||
// SetCurrentEpochAttestations for the beacon state. Updates the entire
|
||||
// list to a new value by overwriting the previous one.
|
||||
func (b *BeaconState) SetCurrentEpochAttestations(val []*pbp2p.PendingAttestation) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -559,7 +559,7 @@ func (b *BeaconState) SetCurrentEpochAttestations(val []*pbp2p.PendingAttestatio
|
||||
return nil
|
||||
}
|
||||
|
||||
// AppendHistoricalRoots for the beacon state. This PR appends the new value
|
||||
// AppendHistoricalRoots for the beacon state. Appends the new value
|
||||
// to the the end of list.
|
||||
func (b *BeaconState) AppendHistoricalRoots(root [32]byte) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -587,7 +587,7 @@ func (b *BeaconState) AppendHistoricalRoots(root [32]byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AppendCurrentEpochAttestations for the beacon state. This PR appends the new value
|
||||
// AppendCurrentEpochAttestations for the beacon state. Appends the new value
|
||||
// to the the end of list.
|
||||
func (b *BeaconState) AppendCurrentEpochAttestations(val *pbp2p.PendingAttestation) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -617,7 +617,7 @@ func (b *BeaconState) AppendCurrentEpochAttestations(val *pbp2p.PendingAttestati
|
||||
return nil
|
||||
}
|
||||
|
||||
// AppendPreviousEpochAttestations for the beacon state. This PR appends the new value
|
||||
// AppendPreviousEpochAttestations for the beacon state. Appends the new value
|
||||
// to the the end of list.
|
||||
func (b *BeaconState) AppendPreviousEpochAttestations(val *pbp2p.PendingAttestation) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -647,7 +647,7 @@ func (b *BeaconState) AppendPreviousEpochAttestations(val *pbp2p.PendingAttestat
|
||||
return nil
|
||||
}
|
||||
|
||||
// AppendValidator for the beacon state. This PR appends the new value
|
||||
// AppendValidator for the beacon state. Appends the new value
|
||||
// to the the end of list.
|
||||
func (b *BeaconState) AppendValidator(val *ethpb.Validator) error {
|
||||
if !b.HasInnerState() {
|
||||
@@ -677,7 +677,7 @@ func (b *BeaconState) AppendValidator(val *ethpb.Validator) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AppendBalance for the beacon state. This PR appends the new value
|
||||
// AppendBalance for the beacon state. Appends the new value
|
||||
// to the the end of list.
|
||||
func (b *BeaconState) AppendBalance(bal uint64) error {
|
||||
if !b.HasInnerState() {
|
||||
|
||||
@@ -200,7 +200,7 @@ func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) {
|
||||
|
||||
// Merkleize 32-byte leaves into a Merkle trie for its adequate depth, returning
|
||||
// the resulting layers of the trie based on the appropriate depth. This function
|
||||
// pads the leaves to a power-of-two length.
|
||||
// pads the leaves to a length of 32.
|
||||
func merkleize(leaves [][]byte) [][][]byte {
|
||||
hashFunc := hashutil.CustomSHA256Hasher()
|
||||
layers := make([][][]byte, htrutils.GetDepth(uint64(len(leaves)))+1)
|
||||
|
||||
@@ -191,7 +191,7 @@ func (h *stateRootHasher) computeFieldRoots(state *pb.BeaconState) ([][]byte, er
|
||||
// CurrentEpochAttestations slice root.
|
||||
currAttsRoot, err := h.epochAttestationsRoot(state.CurrentEpochAttestations)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not compute previous epoch attestations merkleization")
|
||||
return nil, errors.Wrap(err, "could not compute current epoch attestations merkleization")
|
||||
}
|
||||
fieldRoots[16] = currAttsRoot[:]
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ func (r *reference) MinusRef() {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
// Do not reduce further if object
|
||||
// already has 0 reference to prevent overflow.
|
||||
// already has 0 reference to prevent underflow.
|
||||
if r.refs == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ type Service struct {
|
||||
|
||||
// NewRegularSync service.
|
||||
func NewRegularSync(cfg *Config) *Service {
|
||||
// Intialize block limits.
|
||||
// Initialize block limits.
|
||||
allowedBlocksPerSecond := float64(flags.Get().BlockBatchLimit)
|
||||
allowedBlocksBurst := int64(flags.Get().BlockBatchLimitBurstFactor * flags.Get().BlockBatchLimit)
|
||||
|
||||
|
||||
@@ -21,21 +21,21 @@ func ToBytes(x uint64, length int) []byte {
|
||||
return bytes[:length]
|
||||
}
|
||||
|
||||
// Bytes1 returns integer x to bytes in little-endian format, x.to_bytes(1, 'big').
|
||||
// Bytes1 returns integer x to bytes in little-endian format, x.to_bytes(1, 'little').
|
||||
func Bytes1(x uint64) []byte {
|
||||
bytes := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(bytes, x)
|
||||
return bytes[:1]
|
||||
}
|
||||
|
||||
// Bytes2 returns integer x to bytes in little-endian format, x.to_bytes(2, 'big').
|
||||
// Bytes2 returns integer x to bytes in little-endian format, x.to_bytes(2, 'little').
|
||||
func Bytes2(x uint64) []byte {
|
||||
bytes := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(bytes, x)
|
||||
return bytes[:2]
|
||||
}
|
||||
|
||||
// Bytes3 returns integer x to bytes in little-endian format, x.to_bytes(3, 'big').
|
||||
// Bytes3 returns integer x to bytes in little-endian format, x.to_bytes(3, 'little').
|
||||
func Bytes3(x uint64) []byte {
|
||||
bytes := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(bytes, x)
|
||||
|
||||
@@ -116,8 +116,8 @@ func IsUint64Sorted(a []uint64) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// NotUint64 returns the uint64 in slice a that are
|
||||
// not in slice b with time complexity of approximately
|
||||
// NotUint64 returns the uint64 in slice b that are
|
||||
// not in slice a with time complexity of approximately
|
||||
// O(n) leveraging a map to check for element existence
|
||||
// off by a constant factor of underlying map efficiency.
|
||||
func NotUint64(a []uint64, b []uint64) []uint64 {
|
||||
@@ -231,7 +231,7 @@ func IsInInt64(a int64, b []int64) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// UnionByteSlices returns the common elements between sets of byte slices.
|
||||
// UnionByteSlices returns the all elements between sets of byte slices.
|
||||
func UnionByteSlices(s ...[][]byte) [][]byte {
|
||||
if len(s) == 0 {
|
||||
return [][]byte{}
|
||||
|
||||
@@ -14,8 +14,8 @@ var (
|
||||
}
|
||||
InteropNumValidators = &cli.Uint64Flag{
|
||||
Name: "interop-num-validators",
|
||||
Usage: "The number of validators to deterministically generate when used in combination with " +
|
||||
"--interop-num-validators. Example: --interop-start-index=5 --interop-num-validators=3 would generate " +
|
||||
Usage: "The number of validators to deterministically generate. " +
|
||||
"Example: --interop-start-index=5 --interop-num-validators=3 would generate " +
|
||||
"keys from index 5 to 7.",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -336,7 +336,7 @@ func clearDB(dataDir string, pubkeys [][48]byte, force bool) error {
|
||||
deniedText := "The historical actions database will not be deleted. No changes have been made."
|
||||
clearDBConfirmed, err = cmd.ConfirmAction(actionText, deniedText)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not create DB in dir %s", dataDir)
|
||||
return errors.Wrapf(err, "Could not clear DB in dir %s", dataDir)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user