Skip to content

Commit ae73aa3

Browse files
authored
Merge pull request #1127 from rocket-pool/replace-fastssz-dynamicssz
Replace fastssz with dynamic-ssz
2 parents fbb355b + d1eabae commit ae73aa3

34 files changed

Lines changed: 24828 additions & 11452 deletions

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ require (
3232
github.com/klauspost/compress v1.17.9
3333
github.com/mitchellh/go-homedir v1.1.0
3434
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
35+
github.com/pk910/dynamic-ssz v1.3.2
3536
github.com/princjef/gomarkdoc v0.4.1
3637
github.com/prometheus/client_golang v1.20.0
3738
github.com/prysmaticlabs/go-bitfield v0.0.0-20240328144219-a1caa50c3a1e
@@ -64,6 +65,7 @@ require (
6465
github.com/bits-and-blooms/bitset v1.20.0 // indirect
6566
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
6667
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
68+
github.com/casbin/govaluate v1.10.0 // indirect
6769
github.com/cespare/xxhash/v2 v2.3.0 // indirect
6870
github.com/cheggaaa/pb/v3 v3.0.8 // indirect
6971
github.com/cloudflare/circl v1.6.3 // indirect
@@ -146,6 +148,7 @@ require (
146148
github.com/opencontainers/image-spec v1.0.2 // indirect
147149
github.com/opentracing/opentracing-go v1.2.0 // indirect
148150
github.com/pjbgf/sha1cd v0.6.0 // indirect
151+
github.com/pk910/hashtree-bindings v0.2.2 // indirect
149152
github.com/pkg/errors v0.9.1 // indirect
150153
github.com/polydawn/refmt v0.89.1-0.20231129105047-37766d95467a // indirect
151154
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
@@ -188,9 +191,11 @@ require (
188191
go.uber.org/multierr v1.11.0 // indirect
189192
go.uber.org/zap v1.27.0 // indirect
190193
golang.org/x/crypto v0.52.0 // indirect
194+
golang.org/x/mod v0.35.0 // indirect
191195
golang.org/x/net v0.55.0 // indirect
192196
golang.org/x/oauth2 v0.35.0 // indirect
193197
golang.org/x/sys v0.45.0 // indirect
198+
golang.org/x/tools v0.44.0 // indirect
194199
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
195200
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
196201
google.golang.org/grpc v1.80.0 // indirect
@@ -202,3 +207,5 @@ require (
202207
)
203208

204209
replace github.com/wealdtech/go-merkletree v1.0.1-0.20190605192610-2bb163c2ea2a => github.com/rocket-pool/go-merkletree v1.0.1-0.20220406020931-c262d9b976dd
210+
211+
tool github.com/pk910/dynamic-ssz/dynssz-gen

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku
113113
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
114114
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
115115
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
116+
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
117+
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
116118
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
117119
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
118120
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
@@ -783,6 +785,10 @@ github.com/pion/webrtc/v3 v3.3.0 h1:Rf4u6n6U5t5sUxhYPQk/samzU/oDv7jk6BA5hyO2F9I=
783785
github.com/pion/webrtc/v3 v3.3.0/go.mod h1:hVmrDJvwhEertRWObeb1xzulzHGeVUoPlWvxdGzcfU0=
784786
github.com/pjbgf/sha1cd v0.6.0 h1:3WJ8Wz8gvDz29quX1OcEmkAlUg9diU4GxJHqs0/XiwU=
785787
github.com/pjbgf/sha1cd v0.6.0/go.mod h1:lhpGlyHLpQZoxMv8HcgXvZEhcGs0PG/vsZnEJ7H0iCM=
788+
github.com/pk910/dynamic-ssz v1.3.2 h1:65UR/O+ss+U2Dn86Rdl7LwehHo3u2ElutduS/pcuUXE=
789+
github.com/pk910/dynamic-ssz v1.3.2/go.mod h1:lqmnou2bjr2UWQ3C/L3082TGW0SFl/SwT7ionwM0+FU=
790+
github.com/pk910/hashtree-bindings v0.2.2 h1:gkczxxekBW2NeMK9N3OLj7Jepe7zPmJGVwr8LyofGsA=
791+
github.com/pk910/hashtree-bindings v0.2.2/go.mod h1:zrWt88783JmhBfcgni6kkIMYRdXTZi/FL//OyI5T/l4=
786792
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
787793
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
788794
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

shared/services/beacon/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,18 @@ const (
156156

157157
// SSZ response go into these wrapper types.
158158
// You can stream Data into a deserializer.
159+
// Size is the total SSZ payload size from Content-Length; <= 0 if unknown.
159160
// Fork is the consensus version, e.g, "deneb" or "electra"
160161

161162
type BeaconStateSSZ struct {
162163
Data io.ReadCloser
164+
Size int64
163165
Fork string
164166
}
165167

166168
type BeaconBlockSSZ struct {
167169
Data io.ReadCloser
170+
Size int64
168171
Fork string
169172
}
170173

shared/services/beacon/client/std-http-client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ func (c *StandardHttpClient) GetBeaconStateSSZ(slot uint64) (*beacon.BeaconState
10281028

10291029
return &beacon.BeaconStateSSZ{
10301030
Data: response.Body,
1031+
Size: response.ContentLength,
10311032
Fork: response.Header.Get(ResponseConsensusVersionHeader),
10321033
}, nil
10331034
}
@@ -1050,6 +1051,7 @@ func (c *StandardHttpClient) GetBeaconBlockSSZ(slot uint64) (*beacon.BeaconBlock
10501051

10511052
return &beacon.BeaconBlockSSZ{
10521053
Data: response.Body,
1054+
Size: response.ContentLength,
10531055
Fork: response.Header.Get(ResponseConsensusVersionHeader),
10541056
}, true, nil
10551057
}
@@ -1213,6 +1215,10 @@ func (c *StandardHttpClient) sszRequest(requestPath string) (*http.Response, err
12131215
return nil, err
12141216
}
12151217
request.Header.Set("Accept", RequestSSZContentType)
1218+
// Disable transparent compression: a compressed response has no
1219+
// Content-Length, which would force the buffered (non-streaming) SSZ
1220+
// decode path
1221+
request.Header.Set("Accept-Encoding", "identity")
12161222
return http.DefaultClient.Do(request)
12171223
}
12181224

shared/services/megapools.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1515
"github.com/ethereum/go-ethereum/common"
1616
"github.com/ethereum/go-ethereum/crypto"
17-
ssz "github.com/ferranbt/fastssz"
17+
"github.com/pk910/dynamic-ssz/treeproof"
1818
"github.com/urfave/cli/v3"
1919
"golang.org/x/sync/errgroup"
2020

@@ -165,7 +165,7 @@ func GetWithdrawableEpochProof(c *cli.Command, wallet *wallet.Wallet, eth2Config
165165
return api.ValidatorWithdrawableEpochProof{}, err
166166
}
167167

168-
beaconState, err := eth2.NewBeaconState(beaconStateResponse.Data, beaconStateResponse.Fork)
168+
beaconState, err := eth2.NewBeaconState(beaconStateResponse.Data, beaconStateResponse.Size, beaconStateResponse.Fork)
169169
if err != nil {
170170
return api.ValidatorWithdrawableEpochProof{}, err
171171
}
@@ -722,7 +722,7 @@ func GetWithdrawalProofForSlot(c *cli.Command, slot uint64, validatorIndex uint6
722722
return megapool.FinalBalanceProof{}, 0, nil, err
723723
}
724724

725-
beaconState, err := eth2.NewBeaconState(stateResponse.Data, stateResponse.Fork)
725+
beaconState, err := eth2.NewBeaconState(stateResponse.Data, stateResponse.Size, stateResponse.Fork)
726726
if err != nil {
727727
return megapool.FinalBalanceProof{}, 0, nil, err
728728
}
@@ -768,7 +768,7 @@ func GetWithdrawalProofForSlot(c *cli.Command, slot uint64, validatorIndex uint6
768768
if err != nil {
769769
return megapool.FinalBalanceProof{}, 0, nil, err
770770
}
771-
blockRootsState, err := eth2.NewBeaconState(blockRootsStateResponse.Data, blockRootsStateResponse.Fork)
771+
blockRootsState, err := eth2.NewBeaconState(blockRootsStateResponse.Data, blockRootsStateResponse.Size, blockRootsStateResponse.Fork)
772772
if err != nil {
773773
return megapool.FinalBalanceProof{}, 0, nil, err
774774
}
@@ -778,8 +778,8 @@ func GetWithdrawalProofForSlot(c *cli.Command, slot uint64, validatorIndex uint6
778778
}
779779

780780
// Get historical summary proof
781-
var tree *ssz.Node
782-
tree, err = fuluState.GetTree()
781+
var tree *treeproof.Node
782+
tree, err = generic.SSZ.GetTree(fuluState)
783783
if err != nil {
784784
return megapool.FinalBalanceProof{}, 0, nil, fmt.Errorf("could not get state tree: %w", err)
785785
}
@@ -863,7 +863,7 @@ func FindWithdrawalBlockAndArrayPosition(slot uint64, validatorIndex uint64, bc
863863
}
864864
notFounds = 0
865865

866-
beaconBlock, err := eth2.NewSignedBeaconBlock(blockResponse.Data, blockResponse.Fork)
866+
beaconBlock, err := eth2.NewSignedBeaconBlock(blockResponse.Data, blockResponse.Size, blockResponse.Fork)
867867
if err != nil {
868868
return 0, nil, 0, nil, nil, err
869869
}

shared/services/services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func GetBeaconState(bc beacon.Client) (eth2.BeaconState, error) {
231231
return nil, err
232232
}
233233

234-
beaconState, err := eth2.NewBeaconState(beaconStateResponse.Data, beaconStateResponse.Fork)
234+
beaconState, err := eth2.NewBeaconState(beaconStateResponse.Data, beaconStateResponse.Size, beaconStateResponse.Fork)
235235
if err != nil {
236236
return nil, err
237237
}

shared/types/eth2/fork/deneb/block_deneb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "github.com/rocket-pool/smartnode/shared/types/eth2/generic"
66
const BeaconBlockBodyChunksCeil uint64 = 16
77

88
func (b *SignedBeaconBlock) ProveWithdrawal(indexInWithdrawalsArray uint64) ([][]byte, error) {
9-
tree, err := b.Block.GetTree()
9+
tree, err := generic.SSZ.GetTree(b.Block)
1010
if err != nil {
1111
return nil, err
1212
}

0 commit comments

Comments
 (0)