@@ -6,19 +6,19 @@ import (
66 "fmt"
77 "log/slog"
88 "math/big"
9- "strings"
109 "sync"
1110
1211 "github.com/ethereum/go-ethereum"
13- "github.com/ethereum/go-ethereum/accounts/abi"
1412 "github.com/ethereum/go-ethereum/common"
1513 "github.com/strahe/synapse-go/chain"
1614 "github.com/strahe/synapse-go/internal/lifecycle"
1715 "github.com/strahe/synapse-go/payments"
1816 "github.com/strahe/synapse-go/warmstorage"
1917)
2018
21- // ContractCaller is the subset of ethereum.ContractCaller needed by Service.
19+ // ContractCaller is the chain reader accepted by Service. CallContract remains
20+ // part of the public interface for compatibility; current cost calculations
21+ // only use BlockNumber.
2222type ContractCaller interface {
2323 CallContract (ctx context.Context , call ethereum.CallMsg , blockNumber * big.Int ) ([]byte , error )
2424 BlockNumber (ctx context.Context ) (uint64 , error )
@@ -38,15 +38,14 @@ type PaymentsReader interface {
3838// Service computes upload costs and account summaries for the FWSS ecosystem.
3939// All methods are safe for concurrent use.
4040type Service struct {
41- c chain.Chain
42- ws WarmStorageReader
43- pay PaymentsReader
44- caller ContractCaller
45- pdpVerifier common.Address
46- usdfc common.Address
47- fwss common.Address
48- logger * slog.Logger
49- lifecycle * lifecycle.Lifecycle
41+ c chain.Chain
42+ ws WarmStorageReader
43+ pay PaymentsReader
44+ caller ContractCaller
45+ usdfc common.Address
46+ fwss common.Address
47+ logger * slog.Logger
48+ lifecycle * lifecycle.Lifecycle
5049}
5150
5251// Options configures a [Service].
@@ -61,7 +60,7 @@ type Options struct {
6160 // Payments reads account and allowance state. Required.
6261 Payments PaymentsReader
6362
64- // Caller issues eth_call against the configured chain . Required.
63+ // Caller provides chain reads for cost calculations . Required.
6564 Caller ContractCaller
6665
6766 // Logger is the structured logger. If nil, logging is silent.
@@ -92,20 +91,15 @@ func New(opts Options) (*Service, error) {
9291 if addrs .USDFC == (common.Address {}) {
9392 return nil , fmt .Errorf ("costs.New: %w: %v: missing USDFC address" , chain .ErrUnknownChain , opts .Chain )
9493 }
95- if addrs .PDPVerifier == (common.Address {}) {
96- return nil , fmt .Errorf ("costs.New: %w: %v: missing PDPVerifier address" , chain .ErrUnknownChain , opts .Chain )
97- }
98-
9994 return & Service {
100- c : opts .Chain ,
101- ws : opts .WarmStorage ,
102- pay : opts .Payments ,
103- caller : opts .Caller ,
104- pdpVerifier : addrs .PDPVerifier ,
105- usdfc : addrs .USDFC ,
106- fwss : addrs .FWSS ,
107- logger : opts .Logger ,
108- lifecycle : opts .Lifecycle ,
95+ c : opts .Chain ,
96+ ws : opts .WarmStorage ,
97+ pay : opts .Payments ,
98+ caller : opts .Caller ,
99+ usdfc : addrs .USDFC ,
100+ fwss : addrs .FWSS ,
101+ logger : opts .Logger ,
102+ lifecycle : opts .Lifecycle ,
109103 }, nil
110104}
111105
@@ -144,16 +138,15 @@ func (s *Service) GetUploadCosts(
144138 }
145139
146140 var (
147- pricing * warmstorage.ServicePrice
148- account * payments.AccountState
149- approval * payments.OperatorApproval
150- usdfcSybilFee * big.Int
151- mu sync.Mutex
152- errs []error
153- wg sync.WaitGroup
141+ pricing * warmstorage.ServicePrice
142+ account * payments.AccountState
143+ approval * payments.OperatorApproval
144+ mu sync.Mutex
145+ errs []error
146+ wg sync.WaitGroup
154147 )
155148
156- wg .Add (4 )
149+ wg .Add (3 )
157150
158151 go func () {
159152 defer wg .Done ()
@@ -191,18 +184,6 @@ func (s *Service) GetUploadCosts(
191184 approval = ap
192185 }()
193186
194- go func () {
195- defer wg .Done ()
196- fee , err := s .readUsdfcSybilFee (ctx )
197- mu .Lock ()
198- defer mu .Unlock ()
199- if err != nil {
200- errs = append (errs , fmt .Errorf ("USDFC_SYBIL_FEE: %w" , err ))
201- return
202- }
203- usdfcSybilFee = fee
204- }()
205-
206187 wg .Wait ()
207188
208189 if len (errs ) > 0 {
@@ -225,7 +206,7 @@ func (s *Service) GetUploadCosts(
225206 currentDataSetSize ,
226207 pricing ,
227208 DefaultLockupPeriod ,
228- usdfcSybilFee ,
209+ usdfcSybilFeeValue () ,
229210 opts .IsNewDataSet ,
230211 opts .EnableCDN ,
231212 )
@@ -324,50 +305,3 @@ func (s *Service) currentEpoch(ctx context.Context) (*big.Int, error) {
324305 }
325306 return new (big.Int ).SetUint64 (block ), nil
326307}
327-
328- const usdfcSybilFeeABIJSON = `[{
329- "type": "function",
330- "name": "USDFC_SYBIL_FEE",
331- "inputs": [],
332- "outputs": [{"name": "", "type": "uint256"}],
333- "stateMutability": "view"
334- }]`
335-
336- var usdfcSybilFeeABI abi.ABI
337-
338- func init () {
339- var err error
340- usdfcSybilFeeABI , err = abi .JSON (strings .NewReader (usdfcSybilFeeABIJSON ))
341- if err != nil {
342- panic ("costs: failed to parse USDFC_SYBIL_FEE ABI: " + err .Error ()) //nolint:forbidigo // init() ABI parse: error implies a build/codegen bug, not a runtime condition
343- }
344- }
345-
346- func (s * Service ) readUsdfcSybilFee (ctx context.Context ) (* big.Int , error ) {
347- data , err := usdfcSybilFeeABI .Pack ("USDFC_SYBIL_FEE" )
348- if err != nil {
349- return nil , fmt .Errorf ("costs.readUsdfcSybilFee: pack: %w" , err )
350- }
351-
352- result , err := s .caller .CallContract (ctx , ethereum.CallMsg {
353- To : & s .pdpVerifier ,
354- Data : data ,
355- }, nil )
356- if err != nil {
357- return nil , fmt .Errorf ("costs.readUsdfcSybilFee: call: %w" , err )
358- }
359-
360- values , err := usdfcSybilFeeABI .Unpack ("USDFC_SYBIL_FEE" , result )
361- if err != nil {
362- return nil , fmt .Errorf ("costs.readUsdfcSybilFee: unpack: %w" , err )
363- }
364- if len (values ) == 0 {
365- return nil , fmt .Errorf ("costs.readUsdfcSybilFee: empty result" )
366- }
367-
368- fee , ok := values [0 ].(* big.Int )
369- if ! ok {
370- return nil , fmt .Errorf ("costs.readUsdfcSybilFee: unexpected type %T" , values [0 ])
371- }
372- return fee , nil
373- }
0 commit comments