2021-07-27 19:10:08 +00:00
|
|
|
package altair
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/blocks"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
2021-07-27 19:10:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ProcessDeposits processes validator deposits for beacon state Altair.
|
|
|
|
func ProcessDeposits(
|
|
|
|
ctx context.Context,
|
2022-05-20 22:40:03 +00:00
|
|
|
beaconState state.BeaconState,
|
2021-07-27 19:10:08 +00:00
|
|
|
deposits []*ethpb.Deposit,
|
2022-05-20 22:40:03 +00:00
|
|
|
) (state.BeaconState, error) {
|
2021-07-27 19:10:08 +00:00
|
|
|
batchVerified, err := blocks.BatchVerifyDepositsSignatures(ctx, deposits)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, deposit := range deposits {
|
|
|
|
if deposit == nil || deposit.Data == nil {
|
|
|
|
return nil, errors.New("got a nil deposit in block")
|
|
|
|
}
|
2022-06-27 13:34:38 +00:00
|
|
|
beaconState, err = ProcessDeposit(beaconState, deposit, batchVerified)
|
2021-07-27 19:10:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "could not process deposit from %#x", bytesutil.Trunc(deposit.Data.PublicKey))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return beaconState, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProcessDeposit processes validator deposit for beacon state Altair.
|
2022-06-27 13:34:38 +00:00
|
|
|
func ProcessDeposit(beaconState state.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (state.BeaconState, error) {
|
2021-07-31 23:42:07 +00:00
|
|
|
beaconState, isNewValidator, err := blocks.ProcessDeposit(beaconState, deposit, verifySignature)
|
2021-07-27 19:10:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-31 23:42:07 +00:00
|
|
|
if isNewValidator {
|
2021-07-27 19:10:08 +00:00
|
|
|
if err := beaconState.AppendInactivityScore(0); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := beaconState.AppendPreviousParticipationBits(0); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := beaconState.AppendCurrentParticipationBits(0); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return beaconState, nil
|
|
|
|
}
|