func performRoles(slotCtx context.Context, allRoles map[[48]byte][]iface.ValidatorRole, v iface.Validator, slot primitives.Slot) {
for pubKey, roles := range allRoles {
for _, role := range roles {
// 每个角色启动独立的 goroutine 执行
go func(role iface.ValidatorRole, pubKey [fieldparams.BLSPubkeyLength]byte) {
switch role {
case iface.RoleAttester:
// 提交 attestation
v.SubmitAttestation(slotCtx, slot, pubKey)
case iface.RoleProposer:
// 提议区块
v.ProposeBlock(slotCtx, slot, pubKey)
case iface.RoleAggregator:
// 提交聚合证明
v.SubmitAggregateAndProof(slotCtx, slot, pubKey)
}
}(role, pubKey)
}
}
}