Skip to content

Commit ed4d79e

Browse files
committed
Merge branch 'master' into verkle-support
2 parents d7e303f + 515818d commit ed4d79e

File tree

5 files changed

+100
-2
lines changed

5 files changed

+100
-2
lines changed

pkg/coordinator/tasks/generate_blob_transactions/task.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,21 @@ func (t *Task) LoadConfig() error {
133133

134134
func (t *Task) Execute(ctx context.Context) error {
135135
if t.walletPool != nil {
136+
t.logger.Infof("funding wallet: %v [nonce: %v] %v ETH", t.walletPool.GetRootWallet().GetAddress().Hex(), t.walletPool.GetRootWallet().GetNonce(), t.walletPool.GetRootWallet().GetReadableBalance(18, 0, 4, false, false))
137+
136138
err := t.ensureChildWalletFunding(ctx)
137139
if err != nil {
138140
t.logger.Infof("failed ensuring child wallet funding: %v", err)
139141
return err
140142
}
141143

142144
for idx, wallet := range t.walletPool.GetChildWallets() {
143-
t.logger.Infof("wallet #%v: %v [nonce: %v]", idx, wallet.GetAddress().Hex(), wallet.GetNonce())
145+
t.logger.Infof("wallet #%v: %v [nonce: %v] %v ETH", idx, wallet.GetAddress().Hex(), wallet.GetNonce(), wallet.GetReadableBalance(18, 0, 4, false, false))
144146
}
145147

146148
go t.runChildWalletFundingRoutine(ctx)
149+
} else {
150+
t.logger.Infof("wallet: %v [nonce: %v] %v ETH", t.wallet.GetAddress().Hex(), t.wallet.GetNonce(), t.wallet.GetReadableBalance(18, 0, 4, false, false))
147151
}
148152

149153
var subscription *execution.Subscription[*execution.Block]

pkg/coordinator/tasks/generate_deposits/task.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ func (t *Task) generateDeposit(ctx context.Context, accountIdx uint64, validator
276276
return fmt.Errorf("cannot initialize wallet: %w", err)
277277
}
278278

279+
err = wallet.AwaitReady(ctx)
280+
if err != nil {
281+
return fmt.Errorf("cannot load wallet state: %w", err)
282+
}
283+
284+
t.logger.Infof("wallet: %v [nonce: %v] %v ETH", wallet.GetAddress().Hex(), wallet.GetNonce(), wallet.GetReadableBalance(18, 0, 4, false, false))
285+
279286
tx, err := wallet.BuildTransaction(ctx, func(ctx context.Context, nonce uint64, signer bind.SignerFn) (*ethtypes.Transaction, error) {
280287
amount := big.NewInt(int64(data.Amount))
281288
amount.Mul(amount, big.NewInt(1000000000))

pkg/coordinator/tasks/generate_eoa_transactions/task.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,21 @@ func (t *Task) LoadConfig() error {
132132

133133
func (t *Task) Execute(ctx context.Context) error {
134134
if t.walletPool != nil {
135+
t.logger.Infof("funding wallet: %v [nonce: %v] %v ETH", t.walletPool.GetRootWallet().GetAddress().Hex(), t.walletPool.GetRootWallet().GetNonce(), t.walletPool.GetRootWallet().GetReadableBalance(18, 0, 4, false, false))
136+
135137
err := t.ensureChildWalletFunding(ctx)
136138
if err != nil {
137139
t.logger.Infof("failed ensuring child wallet funding: %v", err)
138140
return err
139141
}
140142

141143
for idx, wallet := range t.walletPool.GetChildWallets() {
142-
t.logger.Infof("wallet #%v: %v [nonce: %v]", idx, wallet.GetAddress().Hex(), wallet.GetNonce())
144+
t.logger.Infof("wallet #%v: %v [nonce: %v] %v ETH", idx, wallet.GetAddress().Hex(), wallet.GetNonce(), wallet.GetReadableBalance(18, 0, 4, false, false))
143145
}
144146

145147
go t.runChildWalletFundingRoutine(ctx)
148+
} else {
149+
t.logger.Infof("wallet: %v [nonce: %v] %v ETH", t.wallet.GetAddress().Hex(), t.wallet.GetNonce(), t.wallet.GetReadableBalance(18, 0, 4, false, false))
146150
}
147151

148152
var subscription *execution.Subscription[*execution.Block]

pkg/coordinator/tasks/generate_transaction/task.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ func (t *Task) LoadConfig() error {
126126

127127
//nolint:gocyclo // ignore
128128
func (t *Task) Execute(ctx context.Context) error {
129+
err := t.wallet.AwaitReady(ctx)
130+
if err != nil {
131+
return fmt.Errorf("cannot load wallet state: %w", err)
132+
}
133+
134+
t.logger.Infof("wallet: %v [nonce: %v] %v ETH", t.wallet.GetAddress().Hex(), t.wallet.GetNonce(), t.wallet.GetReadableBalance(18, 0, 4, false, false))
135+
129136
tx, err := t.generateTransaction(ctx)
130137
if err != nil {
131138
return err

pkg/coordinator/wallet/wallet.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/ecdsa"
77
"fmt"
88
"math/big"
9+
"strings"
910
"sync"
1011
"time"
1112

@@ -135,6 +136,81 @@ func (wallet *Wallet) GetNonce() uint64 {
135136
return wallet.confirmedNonce
136137
}
137138

139+
func (wallet *Wallet) GetReadableBalance(unitDigits, maxPreCommaDigitsBeforeTrim, digits int, addPositiveSign, trimAmount bool) string {
140+
// Initialize trimmedAmount and postComma variables to "0"
141+
fullAmount := ""
142+
trimmedAmount := "0"
143+
postComma := "0"
144+
proceed := ""
145+
amount := wallet.GetPendingBalance()
146+
147+
if amount != nil {
148+
s := amount.String()
149+
150+
if amount.Sign() > 0 && addPositiveSign {
151+
proceed = "+"
152+
} else if amount.Sign() < 0 {
153+
proceed = "-"
154+
s = strings.Replace(s, "-", "", 1)
155+
}
156+
157+
l := len(s)
158+
159+
// Check if there is a part of the amount before the decimal point
160+
switch {
161+
case l > unitDigits:
162+
// Calculate length of preComma part
163+
l -= unitDigits
164+
// Set preComma to part of the string before the decimal point
165+
trimmedAmount = s[:l]
166+
// Set postComma to part of the string after the decimal point, after removing trailing zeros
167+
postComma = strings.TrimRight(s[l:], "0")
168+
169+
// Check if the preComma part exceeds the maximum number of digits before the decimal point
170+
if maxPreCommaDigitsBeforeTrim > 0 && l > maxPreCommaDigitsBeforeTrim {
171+
// Reduce the number of digits after the decimal point by the excess number of digits in the preComma part
172+
l -= maxPreCommaDigitsBeforeTrim
173+
if digits < l {
174+
digits = 0
175+
} else {
176+
digits -= l
177+
}
178+
}
179+
// Check if there is only a part of the amount after the decimal point, and no leading zeros need to be added
180+
case l == unitDigits:
181+
// Set postComma to part of the string after the decimal point, after removing trailing zeros
182+
postComma = strings.TrimRight(s, "0")
183+
// Check if there is only a part of the amount after the decimal point, and leading zeros need to be added
184+
case l != 0:
185+
// Use fmt package to add leading zeros to the string
186+
d := fmt.Sprintf("%%0%dd", unitDigits-l)
187+
// Set postComma to resulting string, after removing trailing zeros
188+
postComma = strings.TrimRight(fmt.Sprintf(d, 0)+s, "0")
189+
}
190+
191+
fullAmount = trimmedAmount
192+
if len(postComma) > 0 {
193+
fullAmount += "." + postComma
194+
}
195+
196+
// limit floating part
197+
if len(postComma) > digits {
198+
postComma = postComma[:digits]
199+
}
200+
201+
// set floating point
202+
if len(postComma) > 0 {
203+
trimmedAmount += "." + postComma
204+
}
205+
}
206+
207+
if trimAmount {
208+
return proceed + trimmedAmount
209+
}
210+
211+
return proceed + fullAmount
212+
}
213+
138214
func (wallet *Wallet) AwaitReady(ctx context.Context) error {
139215
select {
140216
case <-ctx.Done():

0 commit comments

Comments
 (0)