Skip to content

Commit

Permalink
feat (service/state): If account doesn't exist at given height, fail …
Browse files Browse the repository at this point in the history
…gracefully (celestiaorg#996)

* feat: if account doesnt exist at given height, fail gracefully

* refactor: instead of returning error, return 0 and log out err on node side

* log: remove prompt to wait for sync as will be resolved by new head determination from syncer
  • Loading branch information
renaynay committed Aug 15, 2022
1 parent 1390c40 commit 93182fc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions service/state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
proofutils "github.com/cosmos/ibc-go/v4/modules/core/23-commitment/types"
logging "github.com/ipfs/go-log/v2"
rpcclient "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/client/http"
"google.golang.org/grpc"
Expand All @@ -21,6 +22,8 @@ import (
"github.com/celestiaorg/nmt/namespace"
)

var log = logging.Logger("state")

// CoreAccessor implements Accessor over a gRPC connection
// with a celestia-core node.
type CoreAccessor struct {
Expand Down Expand Up @@ -157,6 +160,14 @@ func (ca *CoreAccessor) BalanceForAddress(ctx context.Context, addr Address) (*B
}
// unmarshal balance information
value := result.Response.Value
// if the value returned is empty, the account balance does not yet exist
if len(value) == 0 {
log.Errorf("balance for account %s does not exist at block height %d", addr.String(), head.Height)
return &Balance{
Denom: app.BondDenom,
Amount: sdktypes.NewInt(0),
}, nil
}
coin, ok := sdktypes.NewIntFromString(string(value))
if !ok {
return nil, fmt.Errorf("cannot convert %s into sdktypes.Int", string(value))
Expand Down

0 comments on commit 93182fc

Please sign in to comment.