@@ -626,26 +626,23 @@ func claimEverything(cmd *cobra.Command) error {
626626 log .Info ().Uint32 ("networkID" , currentNetworkID ).Msg ("current network" )
627627
628628 concurrency := 3
629- workPool := make (chan struct {} , concurrency ) // Bounded chan for controlled concurrency
629+ workPool := make (chan * BridgeDeposit , concurrency ) // bounded chan for controlled concurrency
630630
631- nonceCounter , err := currentNonce (cmd .Context (), client , privateKey )
631+ nonceCounter , err := currentNonce (cmd .Context (), client , destinationAddress )
632632 if err != nil {
633633 return err
634634 }
635635 log .Info ().Int64 ("nonce" , nonceCounter .Int64 ()).Msg ("starting nonce" )
636636 nonceMutex := sync.Mutex {}
637637 nonceIncrement := big .NewInt (1 )
638- retryNonces := make (chan * big.Int , concurrency ) // bounded so can async hand off
639-
638+ retryNonces := make (chan * big.Int , concurrency ) // bounded same as workPool
639+
640640 for _ , d := range depositMap {
641-
642- workPool <- struct {}{} // block until a slot is available
643-
641+ workPool <- d // block until a slot is available
644642 go func (deposit * BridgeDeposit ) {
645643 defer func () {
646644 <- workPool // release work slot
647645 }()
648-
649646 if deposit .DestNet != currentNetworkID {
650647 log .Debug ().Uint32 ("destination_network" , deposit .DestNet ).Msg ("discarding deposit for different network" )
651648 return
@@ -654,7 +651,6 @@ func claimEverything(cmd *cobra.Command) error {
654651 log .Info ().Str ("txhash" , deposit .ClaimTxHash ).Msg ("It looks like this tx was already claimed" )
655652 return
656653 }
657-
658654 // Either use the next retry nonce, or set and increment the next one
659655 var nextNonce * big.Int
660656 select {
@@ -689,7 +685,7 @@ func claimEverything(cmd *cobra.Command) error {
689685 if strings .Contains (dErr .Error (), "nonce is too low" ) {
690686 return
691687 }
692-
688+ // are there other cases?
693689 retryNonces <- nextNonce
694690 return
695691 }
@@ -703,17 +699,11 @@ func claimEverything(cmd *cobra.Command) error {
703699 return nil
704700}
705701
706- func currentNonce (ctx context.Context , client * ethclient.Client , privateKey string ) (* big.Int , error ) {
707- ecdsa , err := crypto .HexToECDSA (strings .TrimPrefix (privateKey , "0x" ))
708- if err != nil {
709- log .Error ().Err (err ).Msg ("Unable to read private key" )
710- return nil , err
711- }
712- address := crypto .PubkeyToAddress (ecdsa .PublicKey )
713-
714- nonce , err := client .NonceAt (ctx , address , nil )
702+ func currentNonce (ctx context.Context , client * ethclient.Client , address string ) (* big.Int , error ) {
703+ addr := common .HexToAddress (address )
704+ nonce , err := client .NonceAt (ctx , addr , nil )
715705 if err != nil {
716- log .Error ().Err (err ).Str ("address" , address .Hex ()).Msg ("Failed to get nonce" )
706+ log .Error ().Err (err ).Str ("address" , addr .Hex ()).Msg ("Failed to get nonce" )
717707 return nil , err
718708 }
719709 n := int64 (nonce )
0 commit comments