fix(lotus-sim): fund multiple times

Sometimes, a miner is deep in the red.
This commit is contained in:
Steven Allen 2021-06-10 07:39:29 -07:00
parent be713ec04a
commit 783dc5a33d
2 changed files with 28 additions and 18 deletions

View File

@ -33,11 +33,18 @@ var (
taxMin = abi.TokenAmount(types.MustParseFIL("1000FIL")) taxMin = abi.TokenAmount(types.MustParseFIL("1000FIL"))
) )
func fund(send packFunc, target address.Address) error { func fund(send packFunc, target address.Address, times int) error {
amt := targetFunds
if times >= 1 {
if times >= 8 {
times = 8 // cap
}
amt = big.Lsh(amt, uint(times))
}
_, err := send(&types.Message{ _, err := send(&types.Message{
From: fundAccount, From: fundAccount,
To: target, To: target,
Value: targetFunds, Value: amt,
Method: builtin.MethodSend, Method: builtin.MethodSend,
}) })
return err return err
@ -49,23 +56,26 @@ func fund(send packFunc, target address.Address) error {
// 2. If that fails, it checks to see if the exit code was ErrInsufficientFunds. // 2. If that fails, it checks to see if the exit code was ErrInsufficientFunds.
// 3. If so, it sends 1K FIL from the "burnt funds actor" (because we need to send it from // 3. If so, it sends 1K FIL from the "burnt funds actor" (because we need to send it from
// somewhere) and re-tries the message.0 // somewhere) and re-tries the message.0
// func sendAndFund(send packFunc, msg *types.Message) (res *types.MessageReceipt, err error) {
// NOTE: If the message fails a second time, the funds won't be "unsent". for i := 0; i < 10; i++ {
func sendAndFund(send packFunc, msg *types.Message) (*types.MessageReceipt, error) { res, err = send(msg)
res, err := send(msg) if err != nil {
aerr, ok := err.(aerrors.ActorError) return res, nil
if !ok || aerr.RetCode() != exitcode.ErrInsufficientFunds { }
return res, err aerr, ok := err.(aerrors.ActorError)
} if !ok || aerr.RetCode() != exitcode.ErrInsufficientFunds {
// Ok, insufficient funds. Let's fund this miner and try again. return nil, err
err = fund(send, msg.To) }
if err != nil {
if err != ErrOutOfGas { // Ok, insufficient funds. Let's fund this miner and try again.
err = xerrors.Errorf("failed to fund %s: %w", msg.To, err) if err := fund(send, msg.To, i); err != nil {
if err != ErrOutOfGas {
err = xerrors.Errorf("failed to fund %s: %w", msg.To, err)
}
return nil, err
} }
return nil, err
} }
return send(msg) return res, err
} }
func (ss *simulationState) packFunding(ctx context.Context, cb packFunc) (_err error) { func (ss *simulationState) packFunding(ctx context.Context, cb packFunc) (_err error) {

View File

@ -122,7 +122,7 @@ func (ss *simulationState) packPreCommitsMiner(ctx context.Context, cb packFunc,
} }
if big.Cmp(minerBalance, minFunds) < 0 { if big.Cmp(minerBalance, minFunds) < 0 {
err := fund(cb, minerAddr) err := fund(cb, minerAddr, 1)
if err != nil { if err != nil {
if err == ErrOutOfGas { if err == ErrOutOfGas {
return 0, true, nil return 0, true, nil