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

feat(state): enable fee granting #3304

Merged
merged 11 commits into from
Apr 16, 2024
6 changes: 4 additions & 2 deletions nodebuilder/state/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package state

import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"

"github.com/celestiaorg/celestia-node/state"
)

var defaultKeyringBackend = keyring.BackendTest
Expand All @@ -11,14 +13,14 @@ var defaultKeyringBackend = keyring.BackendTest
type Config struct {
KeyringAccName string
KeyringBackend string
GranterAddress string
GranterAddress state.AccAddress
}

func DefaultConfig() Config {
return Config{
KeyringAccName: "",
KeyringBackend: defaultKeyringBackend,
GranterAddress: "",
GranterAddress: state.AccAddress{},
}
}

Expand Down
8 changes: 4 additions & 4 deletions nodebuilder/state/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func coreAccessor(
signer *apptypes.KeyringSigner,
sync *sync.Syncer[*header.ExtendedHeader],
fraudServ libfraud.Service[*header.ExtendedHeader],
granterEnabled string,
) (*state.CoreAccessor, Module, *modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader], error) {
ca, err := state.NewCoreAccessor(signer, sync, corecfg.IP, corecfg.RPCPort, corecfg.GRPCPort, granterEnabled)
opts ...state.Option,
) (*state.CoreAccessor, Module, *modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader]) {
ca := state.NewCoreAccessor(signer, sync, corecfg.IP, corecfg.RPCPort, corecfg.GRPCPort, opts...)
sBreaker := &modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader]{
Service: ca,
FraudType: byzantine.BadEncoding,
FraudServ: fraudServ,
}
return ca, ca, sBreaker, err
return ca, ca, sBreaker
}
11 changes: 10 additions & 1 deletion nodebuilder/state/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package state
import (
"fmt"

sdktypes "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
)
Expand Down Expand Up @@ -36,5 +37,13 @@ func ParseFlags(cmd *cobra.Command, cfg *Config) {
}

cfg.KeyringBackend = cmd.Flag(keyringBackendFlag).Value.String()
cfg.GranterAddress = cmd.Flag(granterAddressFlag).Value.String()

addr := cmd.Flag(granterAddressFlag).Value.String()
if addr != "" {
sdkAddress, err := sdktypes.AccAddressFromBech32(addr)
if err != nil {
panic(err)
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
}
cfg.GranterAddress = sdkAddress
}
}
13 changes: 12 additions & 1 deletion nodebuilder/state/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
logging "github.com/ipfs/go-log/v2"
"go.uber.org/fx"

apptypes "github.com/celestiaorg/celestia-app/x/blob/types"
libfraud "github.com/celestiaorg/go-fraud"
"github.com/celestiaorg/go-header/sync"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/libs/fxutil"
"github.com/celestiaorg/celestia-node/nodebuilder/core"
Expand All @@ -26,7 +30,14 @@ func ConstructModule(tp node.Type, cfg *Config, coreCfg *core.Config) fx.Option
fx.Supply(*cfg),
fx.Supply(cfg.GranterAddress),
fx.Error(cfgErr),
fxutil.ProvideIf(coreCfg.IsEndpointConfigured(), fx.Annotate(coreAccessor,
fxutil.ProvideIf(coreCfg.IsEndpointConfigured(), fx.Annotate(
renaynay marked this conversation as resolved.
Show resolved Hide resolved
func(
signer *apptypes.KeyringSigner,
sync *sync.Syncer[*header.ExtendedHeader],
fraudServ libfraud.Service[*header.ExtendedHeader],
) (*state.CoreAccessor, Module, *modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader]) {
return coreAccessor(*coreCfg, signer, sync, fraudServ, state.WithGranter(cfg.GranterAddress))
},
fx.OnStart(func(ctx context.Context,
breaker *modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader]) error {
return breaker.Start(ctx)
Expand Down
33 changes: 21 additions & 12 deletions state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ const (
gasMultiplier = 1.1
)

// Option is the functional option that is applied to the coreAccessor instance
// to configure parameters.
type Option func(ca *CoreAccessor)

// WithGranter is a functional option to configure the granter address parameter.
func WithGranter(addr AccAddress) Option {
return func(ca *CoreAccessor) {
ca.granter = addr
}
}

// CoreAccessor implements service over a gRPC connection
// with a celestia-core node.
type CoreAccessor struct {
Expand Down Expand Up @@ -94,29 +105,27 @@ func NewCoreAccessor(
coreIP,
rpcPort string,
grpcPort string,
granter string,
) (*CoreAccessor, error) {
options ...Option,
) *CoreAccessor {
// create verifier
prt := merkle.DefaultProofRuntime()
prt.RegisterOpDecoder(storetypes.ProofOpIAVLCommitment, storetypes.CommitmentOpDecoder)
prt.RegisterOpDecoder(storetypes.ProofOpSimpleMerkleCommitment, storetypes.CommitmentOpDecoder)

var (
sdkAddress = AccAddress{}
err error
)
if granter != "" {
sdkAddress, err = sdktypes.AccAddressFromBech32(granter)
}
return &CoreAccessor{
ca := &CoreAccessor{
signer: signer,
getter: getter,
coreIP: coreIP,
rpcPort: rpcPort,
grpcPort: grpcPort,
prt: prt,
granter: sdkAddress,
}, err
}

for _, opt := range options {
opt(ca)
}
return ca

}

func (ca *CoreAccessor) Start(ctx context.Context) error {
Expand Down
5 changes: 2 additions & 3 deletions state/core_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ func TestSubmitPayForBlob(t *testing.T) {
defer cancel()

signer := blobtypes.NewKeyringSigner(cctx.Keyring, accounts[0], cctx.ChainID)
ca, err := NewCoreAccessor(signer, nil, "127.0.0.1", extractPort(rpcAddr), extractPort(grpcAddr), "")
require.NoError(t, err)
ca := NewCoreAccessor(signer, nil, "127.0.0.1", extractPort(rpcAddr), extractPort(grpcAddr))
// start the accessor
err = ca.Start(ctx)
err := ca.Start(ctx)
require.NoError(t, err)
t.Cleanup(func() {
_ = ca.Stop(ctx)
Expand Down
5 changes: 2 additions & 3 deletions state/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.accounts = cfg.Accounts

signer := blobtypes.NewKeyringSigner(s.cctx.Keyring, s.accounts[0], s.cctx.ChainID)
accessor, err := NewCoreAccessor(signer, localHeader{s.cctx.Client}, "", "", "", "")
require.NoError(s.T(), err)
accessor := NewCoreAccessor(signer, localHeader{s.cctx.Client}, "", "", "")
setClients(accessor, s.cctx.GRPCClient, s.cctx.Client)
s.accessor = accessor

// required to ensure the Head request is non-nil
_, err = s.cctx.WaitForHeight(3)
_, err := s.cctx.WaitForHeight(3)
require.NoError(s.T(), err)
}

Expand Down
Loading