2023-09-27 17:09:36 +00:00
|
|
|
package pool
|
|
|
|
|
|
|
|
import (
|
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
2023-10-21 23:17:18 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/crypto/blake2b"
|
2023-09-27 17:09:36 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/clparams"
|
|
|
|
"github.com/ledgerwatch/erigon/cl/cltypes"
|
|
|
|
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DoubleSignatureKey uses blake2b algorithm to merge two signatures together. blake2 is faster than sha3.
|
|
|
|
func doubleSignatureKey(one, two libcommon.Bytes96) (out libcommon.Bytes96) {
|
2023-09-29 21:42:07 +00:00
|
|
|
res := blake2b.Sum256(append(one[:], two[:]...))
|
2023-09-27 17:09:36 +00:00
|
|
|
copy(out[:], res[:])
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func ComputeKeyForProposerSlashing(slashing *cltypes.ProposerSlashing) libcommon.Bytes96 {
|
|
|
|
return doubleSignatureKey(slashing.Header1.Signature, slashing.Header2.Signature)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ComputeKeyForAttesterSlashing(slashing *cltypes.AttesterSlashing) libcommon.Bytes96 {
|
|
|
|
return doubleSignatureKey(slashing.Attestation_1.Signature, slashing.Attestation_2.Signature)
|
|
|
|
}
|
|
|
|
|
|
|
|
// OperationsPool is the collection of all gossip-collectable operations.
|
|
|
|
type OperationsPool struct {
|
2023-09-29 21:42:07 +00:00
|
|
|
AttestationsPool *OperationPool[libcommon.Bytes96, *solid.Attestation]
|
|
|
|
AttesterSlashingsPool *OperationPool[libcommon.Bytes96, *cltypes.AttesterSlashing]
|
|
|
|
ProposerSlashingsPool *OperationPool[libcommon.Bytes96, *cltypes.ProposerSlashing]
|
|
|
|
BLSToExecutionChangesPool *OperationPool[libcommon.Bytes96, *cltypes.SignedBLSToExecutionChange]
|
|
|
|
VoluntaryExistsPool *OperationPool[uint64, *cltypes.SignedVoluntaryExit]
|
2023-09-27 17:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewOperationsPool(beaconCfg *clparams.BeaconChainConfig) OperationsPool {
|
|
|
|
return OperationsPool{
|
2023-09-29 21:42:07 +00:00
|
|
|
AttestationsPool: NewOperationPool[libcommon.Bytes96, *solid.Attestation](int(beaconCfg.MaxAttestations), "attestationsPool"),
|
|
|
|
AttesterSlashingsPool: NewOperationPool[libcommon.Bytes96, *cltypes.AttesterSlashing](int(beaconCfg.MaxAttestations), "attesterSlashingsPool"),
|
|
|
|
ProposerSlashingsPool: NewOperationPool[libcommon.Bytes96, *cltypes.ProposerSlashing](int(beaconCfg.MaxAttestations), "proposerSlashingsPool"),
|
|
|
|
BLSToExecutionChangesPool: NewOperationPool[libcommon.Bytes96, *cltypes.SignedBLSToExecutionChange](int(beaconCfg.MaxBlsToExecutionChanges), "blsExecutionChangesPool"),
|
|
|
|
VoluntaryExistsPool: NewOperationPool[uint64, *cltypes.SignedVoluntaryExit](int(beaconCfg.MaxBlsToExecutionChanges), "voluntaryExitsPool"),
|
2023-09-27 17:09:36 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-29 21:42:07 +00:00
|
|
|
|
|
|
|
func (o *OperationsPool) NotifyBlock(blk *cltypes.BeaconBlock) {
|
|
|
|
blk.Body.VoluntaryExits.Range(func(_ int, exit *cltypes.SignedVoluntaryExit, _ int) bool {
|
|
|
|
o.VoluntaryExistsPool.DeleteIfExist(exit.VoluntaryExit.ValidatorIndex)
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
blk.Body.AttesterSlashings.Range(func(_ int, att *cltypes.AttesterSlashing, _ int) bool {
|
|
|
|
o.AttesterSlashingsPool.DeleteIfExist(ComputeKeyForAttesterSlashing(att))
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
blk.Body.ProposerSlashings.Range(func(_ int, ps *cltypes.ProposerSlashing, _ int) bool {
|
|
|
|
o.ProposerSlashingsPool.DeleteIfExist(ComputeKeyForProposerSlashing(ps))
|
|
|
|
return true
|
|
|
|
})
|
2023-10-01 15:16:55 +00:00
|
|
|
blk.Body.ExecutionChanges.Range(func(_ int, c *cltypes.SignedBLSToExecutionChange, _ int) bool {
|
|
|
|
o.BLSToExecutionChangesPool.DeleteIfExist(c.Signature)
|
|
|
|
return true
|
|
|
|
})
|
2023-09-29 21:42:07 +00:00
|
|
|
}
|