Added concurrent bls (#7709)

This commit is contained in:
Giulio rebuffo 2023-06-12 00:40:03 +02:00 committed by GitHub
parent 4d35e776da
commit 63006611ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 30 deletions

View File

@ -160,6 +160,8 @@ func (b *Eth1Block) DecodeSSZ(buf []byte, version int) error {
b.Extra = solid.NewExtraData() b.Extra = solid.NewExtraData()
b.Transactions = &solid.TransactionsSSZ{} b.Transactions = &solid.TransactionsSSZ{}
b.Withdrawals = solid.NewStaticListSSZ[*types.Withdrawal](16, 44) b.Withdrawals = solid.NewStaticListSSZ[*types.Withdrawal](16, 44)
b.DataGasUsed = new(uint64)
b.ExcessDataGas = new(uint64)
b.version = clparams.StateVersion(version) b.version = clparams.StateVersion(version)
return ssz2.UnmarshalSSZ(buf, version, b.getSchema()...) return ssz2.UnmarshalSSZ(buf, version, b.getSchema()...)
} }
@ -181,7 +183,7 @@ func (b *Eth1Block) getSchema() []interface{} {
s = append(s, b.Withdrawals) s = append(s, b.Withdrawals)
} }
if b.version >= clparams.DenebVersion { if b.version >= clparams.DenebVersion {
s = append(s, &b.DataGasUsed, &b.ExcessDataGas) s = append(s, b.DataGasUsed, b.ExcessDataGas)
} }
return s return s
} }

View File

@ -1,14 +1,11 @@
//go:build spectest
// once all tests are implemented, we can allow this test in the ci build path
package spectest package spectest
import ( import (
"github.com/ledgerwatch/erigon/cl/transition"
"os" "os"
"testing" "testing"
"github.com/ledgerwatch/erigon/cl/transition"
"github.com/ledgerwatch/erigon/cl/spectest/consensus_tests" "github.com/ledgerwatch/erigon/cl/spectest/consensus_tests"
"github.com/ledgerwatch/erigon/spectest" "github.com/ledgerwatch/erigon/spectest"

View File

@ -4,11 +4,12 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"reflect"
"time"
"github.com/ledgerwatch/erigon/cl/transition/impl/eth2/statechange" "github.com/ledgerwatch/erigon/cl/transition/impl/eth2/statechange"
"github.com/ledgerwatch/erigon/metrics/methelp" "github.com/ledgerwatch/erigon/metrics/methelp"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"reflect"
"time"
"github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cl/cltypes/solid" "github.com/ledgerwatch/erigon/cl/cltypes/solid"
@ -704,21 +705,43 @@ func processAttestation(s *state.BeaconState, attestation *solid.Attestation, ba
} }
func verifyAttestations(s *state.BeaconState, attestations *solid.ListSSZ[*solid.Attestation], attestingIndicies [][]uint64) (bool, error) { func verifyAttestations(s *state.BeaconState, attestations *solid.ListSSZ[*solid.Attestation], attestingIndicies [][]uint64) (bool, error) {
var err error indexedAttestations := make([]*cltypes.IndexedAttestation, 0, attestations.Len())
valid := true
attestations.Range(func(idx int, a *solid.Attestation, _ int) bool { attestations.Range(func(idx int, a *solid.Attestation, _ int) bool {
indexedAttestation := state.GetIndexedAttestation(a, attestingIndicies[idx]) indexedAttestations = append(indexedAttestations, state.GetIndexedAttestation(a, attestingIndicies[idx]))
valid, err = state.IsValidIndexedAttestation(s.BeaconState, indexedAttestation)
if err != nil {
return false
}
if !valid {
return false
}
return true return true
}) })
return valid, err return batchVerifyAttestations(s, indexedAttestations)
}
type indexedAttestationVerificationResult struct {
valid bool
err error
}
// Concurrent verification of BLS.
func batchVerifyAttestations(s *state.BeaconState, indexedAttestations []*cltypes.IndexedAttestation) (valid bool, err error) {
c := make(chan indexedAttestationVerificationResult, 1)
for idx := range indexedAttestations {
go func(idx int) {
valid, err := state.IsValidIndexedAttestation(s.BeaconState, indexedAttestations[idx])
c <- indexedAttestationVerificationResult{
valid: valid,
err: err,
}
}(idx)
}
for i := 0; i < len(indexedAttestations); i++ {
result := <-c
if result.err != nil {
return false, err
}
if !result.valid {
return false, nil
}
}
return true, nil
} }
func (I *impl) ProcessBlockHeader(s *state.BeaconState, block *cltypes.BeaconBlock) error { func (I *impl) ProcessBlockHeader(s *state.BeaconState, block *cltypes.BeaconBlock) error {

View File

@ -2,7 +2,8 @@ package main
import ( import (
"flag" "flag"
"net/http"
"github.com/ledgerwatch/erigon/turbo/debug"
"github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice" "github.com/ledgerwatch/erigon/cl/phase1/forkchoice"
@ -41,13 +42,7 @@ func main() {
) )
if *pprof { if *pprof {
// Server for pprof // Server for pprof
go func() { debug.StartPProf("localhost:6060", true)
log.Info("Serving pprof on localhost:6060")
if err := http.ListenAndServe("localhost:6060", nil); err != nil { //nolint:gosec
log.Error("Could not serve pprof", "err", err)
}
}()
} }
if err != nil { if err != nil {

2
go.mod
View File

@ -14,7 +14,7 @@ require (
require ( require (
gfx.cafe/util/go/generic v0.0.0-20230502013805-237fcc25d586 gfx.cafe/util/go/generic v0.0.0-20230502013805-237fcc25d586
github.com/99designs/gqlgen v0.17.32 github.com/99designs/gqlgen v0.17.32
github.com/Giulio2002/bls v0.0.0-20230507111335-fa36c339a11f github.com/Giulio2002/bls v0.0.0-20230611172327-c0b9800e7b57
github.com/RoaringBitmap/roaring v1.2.3 github.com/RoaringBitmap/roaring v1.2.3
github.com/VictoriaMetrics/fastcache v1.12.1 github.com/VictoriaMetrics/fastcache v1.12.1
github.com/VictoriaMetrics/metrics v1.23.1 github.com/VictoriaMetrics/metrics v1.23.1

4
go.sum
View File

@ -18,8 +18,8 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGy
github.com/99designs/gqlgen v0.17.32 h1:yX5On31oZ8I4dAfgZeeR/A8L9SWk+nD+cF8Aao4vmHs= github.com/99designs/gqlgen v0.17.32 h1:yX5On31oZ8I4dAfgZeeR/A8L9SWk+nD+cF8Aao4vmHs=
github.com/99designs/gqlgen v0.17.32/go.mod h1:5j5Ak84e9FTYtH3aaNhK+FoYzXdUAY9CahQcWDqOwR8= github.com/99designs/gqlgen v0.17.32/go.mod h1:5j5Ak84e9FTYtH3aaNhK+FoYzXdUAY9CahQcWDqOwR8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Giulio2002/bls v0.0.0-20230507111335-fa36c339a11f h1:7H8fhLJwlYAzzVUE1bQsQZjJBg8Rw+x5IZyb3i7PfZw= github.com/Giulio2002/bls v0.0.0-20230611172327-c0b9800e7b57 h1:583GFQgWYOAz3dKqHqARVY3KkgebRcJtU4tzy+87gzc=
github.com/Giulio2002/bls v0.0.0-20230507111335-fa36c339a11f/go.mod h1:o6qWofeW8A1XImbo3eHbC/wXnw/dasu0YuHEtdrjYzw= github.com/Giulio2002/bls v0.0.0-20230611172327-c0b9800e7b57/go.mod h1:vwm1rY/WKYdwv5Ii5US2bZ3MQVcHadnev+1Ml2QYWFk=
github.com/RoaringBitmap/roaring v0.4.7/go.mod h1:8khRDP4HmeXns4xIj9oGrKSz7XTQiJx2zgh7AcNke4w= github.com/RoaringBitmap/roaring v0.4.7/go.mod h1:8khRDP4HmeXns4xIj9oGrKSz7XTQiJx2zgh7AcNke4w=
github.com/RoaringBitmap/roaring v0.4.17/go.mod h1:D3qVegWTmfCaX4Bl5CrBE9hfrSrrXIr8KVNvRsDi1NI= github.com/RoaringBitmap/roaring v0.4.17/go.mod h1:D3qVegWTmfCaX4Bl5CrBE9hfrSrrXIr8KVNvRsDi1NI=
github.com/RoaringBitmap/roaring v0.4.23/go.mod h1:D0gp8kJQgE1A4LQ5wFLggQEyvDi06Mq5mKs52e1TwOo= github.com/RoaringBitmap/roaring v0.4.23/go.mod h1:D0gp8kJQgE1A4LQ5wFLggQEyvDi06Mq5mKs52e1TwOo=