Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump default autofund amount & fail fast if not enough balance for autofunding #609

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/powd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func setupFlags() error {
pflag.String("repopath", "~/.powergate", "Path of the repository where Powergate state will be saved.")
pflag.Bool("devnet", false, "Indicate that will be running on an ephemeral devnet. --repopath will be autocleaned on exit.")
pflag.String("ipfsapiaddr", "/ip4/127.0.0.1/tcp/5001", "IPFS API endpoint multiaddress. (Optional, only needed if FFS is used)")
pflag.Int64("walletinitialfund", 4000000000000000, "FFS initial funding transaction amount in attoFIL received by --lotusmasteraddr. (if set)")
pflag.Int64("walletinitialfund", 250_000_000_000_000_000, "FFS initial funding transaction amount in attoFIL received by --lotusmasteraddr. (if set)")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was decided to default to 0.25 FIL in SR2.

pflag.String("gatewayhostaddr", "0.0.0.0:7000", "Gateway host listening address.")
pflag.String("gatewaybasepath", "/", "Gateway base path.")
pflag.String("maxminddbfolder", ".", "Path of the folder containing GeoLite2-City.mmdb")
Expand Down
14 changes: 12 additions & 2 deletions wallet/module/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import (
"github.com/textileio/powergate/lotus"
)

var (
log = logger.Logger("wallet")
const (
feeThreshold = 1_000_000
)

var (
log = logger.Logger("wallet")
networkFaucet = map[string]string{
"nerpanet": "https://faucet.nerpa.interplanetary.dev",
}
Expand Down Expand Up @@ -92,6 +95,13 @@ func (m *Module) NewAddress(ctx context.Context, typ string) (string, error) {
}

if m.masterAddr != address.Undef {
balance, err := client.WalletBalance(ctx, m.masterAddr)
if err != nil {
return "", fmt.Errorf("getting balance from master addr: %s", err)
}
if balance.LessThan(types.BigAdd(types.BigInt{Int: m.iAmount}, types.NewInt(feeThreshold))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fail fast if most prob the txn will fail if we don't have enough funds. The txn is sent async since is a blocking process in the Lotus API now since has to estimate feeds and that takes time.

We still have two improvements to do here:

  • Instead of using feeThreshold as a constant, we could craft a more dynamic calculation of estimated fees. (autofunding: dynamic calculation of fee limit #610)
  • Think about a possibly more reliable way to send the funding txn. If for some wild reason the sent txn failed, we'd get some unwanted result of a 0 balance addr. So looks like we should have a better tracking mechanism about this... not sure though what might be a good solution apart from just retrying with some exponential backoff. (autofunding: more reliable track of funding txn #611)

return "", fmt.Errorf("balance %d is less than allowed threshold", balance)
}
go func() {
client, cls, err := m.clientBuilder()
if err != nil {
Expand Down