Skip to content

Commit

Permalink
Added concurrent bls (#7709)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 authored Jun 11, 2023
1 parent 4d35e77 commit 6300661
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 30 deletions.
4 changes: 3 additions & 1 deletion cl/cltypes/eth1_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()...)
}
Expand All @@ -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
}
Expand Down
7 changes: 2 additions & 5 deletions cl/spectest/tests_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
49 changes: 36 additions & 13 deletions cl/transition/impl/eth2/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 3 additions & 8 deletions cmd/caplin-regression/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 6300661

Please sign in to comment.