Skip to content

Commit cc1cb27

Browse files
committed
fix: address for registration dry run
1 parent c2ecfe4 commit cc1cb27

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

client/epoch/registry_utils.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,14 @@ func (r *registryContractClientImpl) sendRegisterVoter(ctx context.Context, next
227227
return fmt.Errorf("setting gas: %w", err)
228228
}
229229

230+
useOldAddress, contractAddress := shouldUseOldRegistry(epochID, r.registryAddress)
231+
230232
estimatedGasLimit, err := chain.DryRunTxAbi(
231233
ctx,
232234
r.ethClient,
233235
chain.DefaultTxTimeout,
234236
r.senderTxOpts.From,
235-
r.registryAddress,
237+
contractAddress,
236238
common.Big0,
237239
registryAbi,
238240
"registerVoter",
@@ -251,7 +253,7 @@ func (r *registryContractClientImpl) sendRegisterVoter(ctx context.Context, next
251253

252254
var tx *types.Transaction
253255

254-
if shouldUseOldRegistry(epochID, r.registryAddress) {
256+
if useOldAddress {
255257
tx, err = r.oldRegistry.RegisterVoter(r.senderTxOpts, address, vrsSignature)
256258
if err != nil {
257259
return fmt.Errorf("sending registry old tx: %w", err)
@@ -304,20 +306,22 @@ func (r *registryContractClientImpl) sendPreRegisterVoter(ctx context.Context, n
304306
return fmt.Errorf("setting gas pre registry: %w", err)
305307
}
306308

309+
useOldAddress, contractAddress := shouldUseOldPreRegistry(epochID, r.preregistryAddress)
310+
307311
estimatedGasLimit, err := chain.DryRunTxAbi(
308312
ctx,
309313
r.ethClient,
310314
chain.DefaultTxTimeout,
311315
r.senderTxOpts.From,
312-
r.preregistryAddress,
316+
contractAddress,
313317
common.Big0,
314318
preregistryAbi,
315319
"preRegisterVoter",
316320
address,
317321
vrsSignature,
318322
)
319323
if err != nil {
320-
return fmt.Errorf("dry run failed, %w", err)
324+
return fmt.Errorf("dry run failed: %w", err)
321325
}
322326

323327
if r.gasCfg.GasLimit != 0 {
@@ -328,7 +332,7 @@ func (r *registryContractClientImpl) sendPreRegisterVoter(ctx context.Context, n
328332

329333
var tx *types.Transaction
330334

331-
if shouldUseOldPreRegistry(epochID, r.preregistryAddress) {
335+
if useOldAddress {
332336
tx, err = r.oldPreregistry.PreRegisterVoter(r.senderTxOpts, address, vrsSignature)
333337
if err != nil {
334338
return fmt.Errorf("sending preregistry tx: %w", err)
@@ -419,20 +423,20 @@ func SetGas(ctx context.Context, txOptions *bind.TransactOpts, client *ethclient
419423
}
420424
}
421425

422-
func shouldUseOldRegistry(epochID uint32, address common.Address) bool {
426+
func shouldUseOldRegistry(epochID uint32, address common.Address) (bool, common.Address) {
423427
if address == newRegistryCoston && epochID < breakingEpochCoston {
424-
return true
428+
return true, oldRegistryCoston
425429
}
426430

427-
return false
431+
return false, address
428432
}
429433

430-
func shouldUseOldPreRegistry(epochID uint32, address common.Address) bool {
434+
func shouldUseOldPreRegistry(epochID uint32, address common.Address) (bool, common.Address) {
431435
if address == newPreRegistryCoston && epochID < breakingEpochCoston {
432-
return true
436+
return true, oldPreRegistryCoston
433437
}
434438

435-
return false
439+
return false, address
436440
}
437441

438442
func (r *registryContractClientImpl) signature(epochID uint32, address common.Address) ([]byte, error) {
@@ -445,12 +449,12 @@ func (r *registryContractClientImpl) signature(epochID uint32, address common.Ad
445449
r.chainID == chainIDCoston && epochID >= breakingEpochCoston:
446450
signature, err = r.createSignatureNew(r.chainID, epochID, address)
447451
if err != nil {
448-
return nil, fmt.Errorf("creating pre registry signature new: %w", err)
452+
return nil, fmt.Errorf("creating new: %w", err)
449453
}
450454
default:
451455
signature, err = r.createSignature(epochID, address)
452456
if err != nil {
453-
return nil, fmt.Errorf("creating pre registry signature old: %w", err)
457+
return nil, fmt.Errorf("creating old: %w", err)
454458
}
455459
}
456460

0 commit comments

Comments
 (0)