From 63006611ecbd019ea2584ec9579f351a099bec62 Mon Sep 17 00:00:00 2001 From: Giulio rebuffo Date: Mon, 12 Jun 2023 00:40:03 +0200 Subject: [PATCH] Added concurrent bls (#7709) --- cl/cltypes/eth1_block.go | 4 ++- cl/spectest/tests_test.go | 7 ++-- cl/transition/impl/eth2/operations.go | 49 ++++++++++++++++++++------- cmd/caplin-regression/main.go | 11 ++---- go.mod | 2 +- go.sum | 4 +-- 6 files changed, 47 insertions(+), 30 deletions(-) diff --git a/cl/cltypes/eth1_block.go b/cl/cltypes/eth1_block.go index 083c8fa80..a31b1916a 100644 --- a/cl/cltypes/eth1_block.go +++ b/cl/cltypes/eth1_block.go @@ -160,6 +160,8 @@ func (b *Eth1Block) DecodeSSZ(buf []byte, version int) error { b.Extra = solid.NewExtraData() b.Transactions = &solid.TransactionsSSZ{} b.Withdrawals = solid.NewStaticListSSZ[*types.Withdrawal](16, 44) + b.DataGasUsed = new(uint64) + b.ExcessDataGas = new(uint64) b.version = clparams.StateVersion(version) return ssz2.UnmarshalSSZ(buf, version, b.getSchema()...) } @@ -181,7 +183,7 @@ func (b *Eth1Block) getSchema() []interface{} { s = append(s, b.Withdrawals) } if b.version >= clparams.DenebVersion { - s = append(s, &b.DataGasUsed, &b.ExcessDataGas) + s = append(s, b.DataGasUsed, b.ExcessDataGas) } return s } diff --git a/cl/spectest/tests_test.go b/cl/spectest/tests_test.go index 09a7a4234..db4fe28c9 100644 --- a/cl/spectest/tests_test.go +++ b/cl/spectest/tests_test.go @@ -1,14 +1,11 @@ -//go:build spectest - -// once all tests are implemented, we can allow this test in the ci build path - package spectest import ( - "github.com/ledgerwatch/erigon/cl/transition" "os" "testing" + "github.com/ledgerwatch/erigon/cl/transition" + "github.com/ledgerwatch/erigon/cl/spectest/consensus_tests" "github.com/ledgerwatch/erigon/spectest" diff --git a/cl/transition/impl/eth2/operations.go b/cl/transition/impl/eth2/operations.go index 29771769f..bc70a7e36 100644 --- a/cl/transition/impl/eth2/operations.go +++ b/cl/transition/impl/eth2/operations.go @@ -4,11 +4,12 @@ import ( "bytes" "errors" "fmt" + "reflect" + "time" + "github.com/ledgerwatch/erigon/cl/transition/impl/eth2/statechange" "github.com/ledgerwatch/erigon/metrics/methelp" "golang.org/x/exp/slices" - "reflect" - "time" "github.com/ledgerwatch/erigon-lib/common" "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) { - var err error - valid := true + indexedAttestations := make([]*cltypes.IndexedAttestation, 0, attestations.Len()) attestations.Range(func(idx int, a *solid.Attestation, _ int) bool { - indexedAttestation := state.GetIndexedAttestation(a, attestingIndicies[idx]) - valid, err = state.IsValidIndexedAttestation(s.BeaconState, indexedAttestation) - if err != nil { - return false - } - if !valid { - return false - } + indexedAttestations = append(indexedAttestations, state.GetIndexedAttestation(a, attestingIndicies[idx])) 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 { diff --git a/cmd/caplin-regression/main.go b/cmd/caplin-regression/main.go index ab114b4c5..7a3abb9c9 100644 --- a/cmd/caplin-regression/main.go +++ b/cmd/caplin-regression/main.go @@ -2,7 +2,8 @@ package main import ( "flag" - "net/http" + + "github.com/ledgerwatch/erigon/turbo/debug" "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" @@ -41,13 +42,7 @@ func main() { ) if *pprof { // Server for pprof - go func() { - 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) - } - - }() + debug.StartPProf("localhost:6060", true) } if err != nil { diff --git a/go.mod b/go.mod index be0113b96..aa102c281 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( require ( gfx.cafe/util/go/generic v0.0.0-20230502013805-237fcc25d586 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/VictoriaMetrics/fastcache v1.12.1 github.com/VictoriaMetrics/metrics v1.23.1 diff --git a/go.sum b/go.sum index a3ae2eb52..17d8530d9 100644 --- a/go.sum +++ b/go.sum @@ -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/go.mod h1:5j5Ak84e9FTYtH3aaNhK+FoYzXdUAY9CahQcWDqOwR8= 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-20230507111335-fa36c339a11f/go.mod h1:o6qWofeW8A1XImbo3eHbC/wXnw/dasu0YuHEtdrjYzw= +github.com/Giulio2002/bls v0.0.0-20230611172327-c0b9800e7b57 h1:583GFQgWYOAz3dKqHqARVY3KkgebRcJtU4tzy+87gzc= +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.17/go.mod h1:D3qVegWTmfCaX4Bl5CrBE9hfrSrrXIr8KVNvRsDi1NI= github.com/RoaringBitmap/roaring v0.4.23/go.mod h1:D0gp8kJQgE1A4LQ5wFLggQEyvDi06Mq5mKs52e1TwOo=