@@ -4,10 +4,10 @@ import (
4
4
"encoding/json"
5
5
"errors"
6
6
"fmt"
7
+ "math/big"
7
8
"os"
8
9
"os/exec"
9
10
"path/filepath"
10
- "strconv"
11
11
"time"
12
12
13
13
"github.com/initia-labs/weave/common"
@@ -350,7 +350,10 @@ const FundMinitiaAccountsWithoutBatchTxInterface = `
350
350
}
351
351
`
352
352
353
- func (lsk * L1SystemKeys ) calculateTotalWantedCoins (state * LaunchState ) (l1Want int64 , daWant int64 , err error ) {
353
+ func (lsk * L1SystemKeys ) calculateTotalWantedCoins (state * LaunchState ) (l1Want * big.Int , daWant * big.Int , err error ) {
354
+ l1Want = new (big.Int )
355
+ daWant = new (big.Int )
356
+
354
357
for _ , acc := range []* types.GenesisAccount {
355
358
lsk .BridgeExecutor ,
356
359
lsk .OutputSubmitter ,
@@ -361,22 +364,23 @@ func (lsk *L1SystemKeys) calculateTotalWantedCoins(state *LaunchState) (l1Want i
361
364
continue
362
365
}
363
366
364
- amount , err := strconv .ParseInt (acc .Coins , 10 , 64 )
365
- if err != nil {
366
- return 0 , 0 , fmt .Errorf ("failed to parse coin amount %s: %v" , acc .Coins , err )
367
+ amount := new (big.Int )
368
+ _ , ok := amount .SetString (acc .Coins , 10 )
369
+ if ! ok {
370
+ return nil , nil , fmt .Errorf ("failed to parse coin amount '%s'" , acc .Coins )
367
371
}
368
372
369
373
if acc == lsk .Challenger && state .batchSubmissionIsCelestia {
370
- daWant += amount
374
+ daWant . Add ( daWant , amount )
371
375
} else {
372
- l1Want += amount
376
+ l1Want . Add ( l1Want , amount )
373
377
}
374
378
}
375
379
376
380
return l1Want , daWant , nil
377
381
}
378
382
379
- func queryChainBalance (binaryPath , rpc , address string ) (map [string ]int64 , error ) {
383
+ func queryChainBalance (binaryPath , rpc , address string ) (map [string ]string , error ) {
380
384
queryCmd := exec .Command (binaryPath , "query" , "bank" , "balances" , address ,
381
385
"--node" , rpc , "--output" , "json" )
382
386
balanceRes , err := queryCmd .CombinedOutput ()
@@ -394,13 +398,9 @@ func queryChainBalance(binaryPath, rpc, address string) (map[string]int64, error
394
398
return nil , fmt .Errorf ("failed to unmarshal balance: %v" , err )
395
399
}
396
400
397
- balanceMap := make (map [string ]int64 )
401
+ balanceMap := make (map [string ]string )
398
402
for _ , bal := range balance .Balances {
399
- amount , err := strconv .ParseInt (bal .Amount , 10 , 64 )
400
- if err != nil {
401
- return nil , fmt .Errorf ("failed to parse balance amount: %v" , err )
402
- }
403
- balanceMap [bal .Denom ] = amount
403
+ balanceMap [bal .Denom ] = bal .Amount
404
404
}
405
405
406
406
return balanceMap , nil
@@ -425,9 +425,14 @@ func (lsk *L1SystemKeys) VerifyGasStationBalances(state *LaunchState) error {
425
425
}
426
426
427
427
// Verify L1 balance
428
- if l1Available := l1Balances [DefaultL1GasDenom ]; l1Available < l1Want {
429
- return fmt .Errorf ("%w: insufficient initia balance: have %d uinit, want %d uinit" ,
430
- ErrInsufficientBalance , l1Available , l1Want )
428
+ l1AvailableBig := new (big.Int )
429
+ if _ , ok := l1AvailableBig .SetString (l1Balances [DefaultL1GasDenom ], 10 ); ! ok {
430
+ return fmt .Errorf ("failed to parse L1 available balance: %s" , l1Balances [DefaultL1GasDenom ])
431
+ }
432
+
433
+ if l1AvailableBig .Cmp (l1Want ) < 0 {
434
+ return fmt .Errorf ("%w: insufficient initia balance: have %s uinit, want %s uinit" ,
435
+ ErrInsufficientBalance , l1AvailableBig .String (), l1Want .String ())
431
436
}
432
437
433
438
// Check Celestia balance if needed
@@ -440,7 +445,7 @@ func (lsk *L1SystemKeys) VerifyGasStationBalances(state *LaunchState) error {
440
445
return nil
441
446
}
442
447
443
- func (lsk * L1SystemKeys ) verifyCelestiaBalance (state * LaunchState , daWant int64 ) error {
448
+ func (lsk * L1SystemKeys ) verifyCelestiaBalance (state * LaunchState , daWant * big. Int ) error {
444
449
gasStationKey , err := config .GetGasStationKey ()
445
450
if err != nil {
446
451
return fmt .Errorf ("failed to get gas station key: %v" , err )
@@ -464,8 +469,15 @@ func (lsk *L1SystemKeys) verifyCelestiaBalance(state *LaunchState, daWant int64)
464
469
}
465
470
466
471
// Verify Celestia balance
467
- if daAvailable := celestiaBalances [DefaultCelestiaGasDenom ]; daAvailable < daWant {
468
- return fmt .Errorf ("%w: have %d utia, want %d utia" , ErrInsufficientBalance , daAvailable , daWant )
472
+ daAvailableBig := new (big.Int )
473
+ if _ , ok := daAvailableBig .SetString (celestiaBalances [DefaultCelestiaGasDenom ], 10 ); ! ok {
474
+ return fmt .Errorf ("failed to parse DA available balance: %s" , celestiaBalances [DefaultCelestiaGasDenom ])
475
+ }
476
+
477
+ if daAvailableBig .Cmp (daWant ) < 0 {
478
+ return fmt .Errorf ("insufficient DA balance. Required: %s%s, Available: %s%s" ,
479
+ daWant .String (), DefaultCelestiaGasDenom ,
480
+ daAvailableBig .String (), DefaultCelestiaGasDenom )
469
481
}
470
482
471
483
return nil
0 commit comments