Skip to content
Open
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
5 changes: 2 additions & 3 deletions cmd/cartesi-rollups-cli/root/deploy/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/util"
"github.com/cartesi/rollups-node/internal/cli"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/internal/model"
"github.com/cartesi/rollups-node/internal/repository/factory"
"github.com/cartesi/rollups-node/pkg/contracts/iapplicationfactory"
Expand Down Expand Up @@ -146,7 +145,7 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
chainId, err := client.ChainID(ctx)
cobra.CheckErr(err)

txOpts, err := auth.GetTransactOpts(ctx, chainId)
txOpts, err := cli.GetTransactOpts(ctx, chainId)
cobra.CheckErr(err)

// pre deployment checks
Expand Down Expand Up @@ -238,7 +237,7 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
if verboseParam || !asJSONParam {
fmt.Fprint(os.Stderr, "deploying...")
}
_, result, err := deployment.Deploy(ctx, client, txOpts)
_, result, err := deployment.Deploy(ctx, client, ethutil.NewStaticTransactOptsFactory(txOpts))
// The revert surface spans the variant's factory plus the constructors it
// invokes; selectors are content-matched, so passing every factory ABI is
// harmless and covers all three deployment variants.
Expand Down
3 changes: 1 addition & 2 deletions cmd/cartesi-rollups-cli/root/deploy/authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/cartesi/rollups-node/internal/cli"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/pkg/contracts/iauthorityfactory"
"github.com/cartesi/rollups-node/pkg/ethutil"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -73,7 +72,7 @@ func runDeployAuthority(cmd *cobra.Command, args []string) {
chainId, err := client.ChainID(ctx)
cobra.CheckErr(err)

txOpts, err := auth.GetTransactOpts(ctx, chainId)
txOpts, err := cli.GetTransactOpts(ctx, chainId)
cobra.CheckErr(err)

deployment, err := buildAuthorityDeployment(cmd, txOpts)
Expand Down
3 changes: 1 addition & 2 deletions cmd/cartesi-rollups-cli/root/deploy/quorum.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/cartesi/rollups-node/internal/cli"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/pkg/contracts/iquorumfactory"
"github.com/cartesi/rollups-node/pkg/ethutil"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -73,7 +72,7 @@ func runDeployQuorum(cmd *cobra.Command, args []string) {
chainID, err := client.ChainID(ctx)
cobra.CheckErr(err)

txOpts, err := auth.GetTransactOpts(ctx, chainID)
txOpts, err := cli.GetTransactOpts(ctx, chainID)
cobra.CheckErr(err)

deployment, err := buildQuorumDeployment(cmd)
Expand Down
7 changes: 3 additions & 4 deletions cmd/cartesi-rollups-cli/root/deposit/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/util"
"github.com/cartesi/rollups-node/internal/cli"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/pkg/contracts/iapplication"
"github.com/cartesi/rollups-node/pkg/contracts/ierc20errors"
"github.com/cartesi/rollups-node/pkg/contracts/ierc20metadata"
Expand Down Expand Up @@ -114,7 +113,7 @@ func runERC20(cmd *cobra.Command, args []string) {
cobra.CheckErr(err)
chainID, err := client.ChainID(ctx)
cobra.CheckErr(err)
txOpts, err := auth.GetTransactOpts(ctx, chainID)
txOpts, err := cli.GetTransactOpts(ctx, chainID)
cobra.CheckErr(err)

if !skipConfirmation {
Expand All @@ -138,7 +137,7 @@ func runERC20(cmd *cobra.Command, args []string) {
if approveParam {
token, err := ierc20metadata.NewIERC20Metadata(tokenAddr, client)
cobra.CheckErr(err)
approveOpts, err := auth.GetTransactOpts(ctx, chainID)
approveOpts, err := cli.GetTransactOpts(ctx, chainID)
cobra.CheckErr(err)
tx, err := token.Approve(approveOpts, portalAddr, amount)
cobra.CheckErr(cli.DecorateRevert(err,
Expand All @@ -154,7 +153,7 @@ func runERC20(cmd *cobra.Command, args []string) {

portal, err := ierc20portal.NewIERC20Portal(portalAddr, client)
cobra.CheckErr(err)
depositOpts, err := auth.GetTransactOpts(ctx, chainID)
depositOpts, err := cli.GetTransactOpts(ctx, chainID)
cobra.CheckErr(err)
tx, err := portal.DepositERC20Tokens(depositOpts, tokenAddr, appAddr, amount, execData)
// The revert can come from three layers: the portal itself
Expand Down
5 changes: 2 additions & 3 deletions cmd/cartesi-rollups-cli/root/execute/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/cartesi/rollups-node/internal/cli"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/internal/repository/factory"
"github.com/cartesi/rollups-node/pkg/contracts/iapplication"
"github.com/cartesi/rollups-node/pkg/ethutil"
Expand Down Expand Up @@ -99,7 +98,7 @@ func run(cmd *cobra.Command, args []string) {
chainId, err := client.ChainID(ctx)
cobra.CheckErr(err)

txOpts, err := auth.GetTransactOpts(ctx, chainId)
txOpts, err := cli.GetTransactOpts(ctx, chainId)
cobra.CheckErr(err)

if !skipConfirmation {
Expand All @@ -117,7 +116,7 @@ func run(cmd *cobra.Command, args []string) {
txHash, err := ethutil.ExecuteOutput(
ctx,
client,
txOpts,
ethutil.NewStaticTransactOptsFactory(txOpts),
app.IApplicationAddress,
outputIndex,
output.RawData,
Expand Down
3 changes: 1 addition & 2 deletions cmd/cartesi-rollups-cli/root/foreclose/foreclose.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/util"
"github.com/cartesi/rollups-node/internal/cli"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/pkg/contracts/iapplication"
)

Expand Down Expand Up @@ -90,7 +89,7 @@ func run(cmd *cobra.Command, args []string) {
chainId, err := client.ChainID(ctx)
cobra.CheckErr(err)

txOpts, err := auth.GetTransactOpts(ctx, chainId)
txOpts, err := cli.GetTransactOpts(ctx, chainId)
cobra.CheckErr(err)

appContract, err := iapplication.NewIApplication(appAddr, client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/util"
"github.com/cartesi/rollups-node/internal/cli"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/pkg/contracts/iapplication"
)

Expand Down Expand Up @@ -102,7 +101,7 @@ func run(cmd *cobra.Command, args []string) {

chainID, err := client.ChainID(ctx)
cobra.CheckErr(err)
txOpts, err := auth.GetTransactOpts(ctx, chainID)
txOpts, err := cli.GetTransactOpts(ctx, chainID)
cobra.CheckErr(err)

appContract, err := iapplication.NewIApplication(appAddr, client)
Expand Down
7 changes: 7 additions & 0 deletions cmd/cartesi-rollups-cli/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
verbose bool
databaseConnection string
blockchainEndpoint string
gasLimit uint64
inputBoxAddress string
)

Expand All @@ -56,6 +57,12 @@ func init() {
cobra.CheckErr(viper.BindPFlag(config.BLOCKCHAIN_HTTP_ENDPOINT, Cmd.PersistentFlags().Lookup("blockchain-http-endpoint")))
cobra.CheckErr(Cmd.PersistentFlags().MarkHidden("blockchain-http-endpoint"))

// Blockchain gas limit
Cmd.PersistentFlags().Uint64Var(&gasLimit, "gas-limit", 0,
"Blockchain gas limit")
cobra.CheckErr(viper.BindPFlag(config.BLOCKCHAIN_GAS_LIMIT, Cmd.PersistentFlags().Lookup("gas-limit")))
cobra.CheckErr(Cmd.PersistentFlags().MarkHidden("gas-limit"))

// Input box address flag
Cmd.PersistentFlags().StringVar(&inputBoxAddress, "inputbox", "",
"Input Box contract address")
Expand Down
9 changes: 5 additions & 4 deletions cmd/cartesi-rollups-cli/root/send/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/cartesi/rollups-node/internal/cli"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/internal/repository/factory"
"github.com/cartesi/rollups-node/pkg/contracts/iapplication"
"github.com/cartesi/rollups-node/pkg/contracts/iinputbox"
Expand Down Expand Up @@ -143,9 +142,11 @@ func run(cmd *cobra.Command, args []string) {
chainId, err := client.ChainID(ctx)
cobra.CheckErr(err)

txOpts, err := auth.GetTransactOpts(ctx, chainId)
txOpts, err := cli.GetTransactOpts(ctx, chainId)
cobra.CheckErr(err)

txOptsFactory := ethutil.NewStaticTransactOptsFactory(txOpts)

// Ask for confirmation unless --yes flag is set
if !skipConfirmation {
fmt.Printf("Preparing to send input to application %v (%v) with account %v\n",
Expand All @@ -159,7 +160,7 @@ func run(cmd *cobra.Command, args []string) {
}

if asyncMode {
txHash, err := ethutil.AddInputAsync(ctx, client, txOpts, iboxAddr, app.IApplicationAddress, payload)
txHash, err := ethutil.AddInputAsync(ctx, client, txOptsFactory, iboxAddr, app.IApplicationAddress, payload)
cobra.CheckErr(cli.DecorateRevert(err, iinputbox.IInputBoxMetaData, iapplication.IApplicationMetaData))
if asJSONParam {
result := cli.SendResult{
Expand All @@ -175,7 +176,7 @@ func run(cmd *cobra.Command, args []string) {
return
}

inputIndex, blockNumber, txHash, err := ethutil.AddInput(ctx, client, txOpts, iboxAddr, app.IApplicationAddress, payload)
inputIndex, blockNumber, txHash, err := ethutil.AddInput(ctx, client, txOptsFactory, iboxAddr, app.IApplicationAddress, payload)
cobra.CheckErr(cli.DecorateRevert(err, iinputbox.IInputBoxMetaData, iapplication.IApplicationMetaData))

if asJSONParam {
Expand Down
3 changes: 1 addition & 2 deletions cmd/cartesi-rollups-cli/root/withdraw/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/util"
"github.com/cartesi/rollups-node/internal/cli"
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/pkg/contracts/iapplication"
"github.com/cartesi/rollups-node/pkg/ethutil"
)
Expand Down Expand Up @@ -109,7 +108,7 @@ func run(cmd *cobra.Command, args []string) {

chainID, err := client.ChainID(ctx)
cobra.CheckErr(err)
txOpts, err := auth.GetTransactOpts(ctx, chainID)
txOpts, err := cli.GetTransactOpts(ctx, chainID)
cobra.CheckErr(err)

appContract, err := iapplication.NewIApplication(appAddr, client)
Expand Down
2 changes: 1 addition & 1 deletion internal/claimer/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (s *Service) broadcastAcceptClaimOrReconcileRevert(
return claimRetryLater(err)
}

txHash, err := s.blockchain.acceptClaimOnBlockchain(app, currEpoch)
txHash, err := s.blockchain.acceptClaimOnBlockchain(s.Context, app, currEpoch)
if err != nil {
outcome, stateErr := s.handleAcceptClaimRevert(err, app, currEpoch)
switch outcome {
Expand Down
34 changes: 23 additions & 11 deletions internal/claimer/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ type iclaimerBlockchain interface {
)

submitClaimToBlockchain(
ctx context.Context,
ic *iconsensus.IConsensus,
application *model.Application,
epoch *model.Epoch,
) (common.Hash, error)

acceptClaimOnBlockchain(
ctx context.Context,
application *model.Application,
epoch *model.Epoch,
) (common.Hash, error)
Expand Down Expand Up @@ -100,27 +102,28 @@ type iclaimerBlockchain interface {
}

type claimerBlockchain struct {
client *ethclient.Client
txOpts *bind.TransactOpts
logger *slog.Logger
defaultBlock config.DefaultBlock
client *ethclient.Client
txOptsFactory ethutil.TransactOptsFactory
logger *slog.Logger
defaultBlock config.DefaultBlock
}

func (cb *claimerBlockchain) claimSubmitterAddress() (common.Address, bool) {
if cb.txOpts == nil {
if cb.txOptsFactory == nil {
return common.Address{}, false
}
return cb.txOpts.From, true
return cb.txOptsFactory.From(), true
}

func (cb *claimerBlockchain) submitClaimToBlockchain(
ctx context.Context,
ic *iconsensus.IConsensus,
application *model.Application,
epoch *model.Epoch,
) (common.Hash, error) {
txHash := common.Hash{}
if cb.txOpts == nil {
return txHash, fmt.Errorf("txOpts is required for claim submission")
if cb.txOptsFactory == nil {
return txHash, fmt.Errorf("txOptsFactory is required for claim submission")
}
if epoch.OutputsMerkleRoot == nil {
return txHash, fmt.Errorf(
Expand All @@ -140,8 +143,12 @@ func (cb *claimerBlockchain) submitClaimToBlockchain(
for i, h := range epoch.OutputsMerkleProof {
proof[i] = h
}
txOpts, err := cb.txOptsFactory.NewTransactOpts(ctx)
if err != nil {
return txHash, fmt.Errorf("creating transaction options for claim submission: %w", err)
}
lastBlockNumber := new(big.Int).SetUint64(epoch.LastBlock)
tx, err := ic.SubmitClaim(cb.txOpts, application.IApplicationAddress,
tx, err := ic.SubmitClaim(txOpts, application.IApplicationAddress,
lastBlockNumber, *epoch.OutputsMerkleRoot, proof)
if err != nil {
cb.logger.Warn("submitClaimToBlockchain:failed",
Expand Down Expand Up @@ -406,11 +413,12 @@ func (cb *claimerBlockchain) getConsensusAddress(
// ClaimStagingPeriodNotOverYet if the math is off; the caller handles that
// revert via handleAcceptClaimRevert.
func (cb *claimerBlockchain) acceptClaimOnBlockchain(
ctx context.Context,
application *model.Application,
epoch *model.Epoch,
) (common.Hash, error) {
txHash := common.Hash{}
if cb.txOpts == nil {
if cb.txOptsFactory == nil {
return txHash, fmt.Errorf("txOpts is required for claim acceptance")
}
if epoch.MachineHash == nil {
Expand All @@ -422,8 +430,12 @@ func (cb *claimerBlockchain) acceptClaimOnBlockchain(
if err != nil {
return txHash, fmt.Errorf("creating IConsensus binding for acceptClaim: %w", err)
}
txOpts, err := cb.txOptsFactory.NewTransactOpts(ctx)
if err != nil {
return txHash, fmt.Errorf("creating transaction options for claim acceptance: %w", err)
}
lastBlockNumber := new(big.Int).SetUint64(epoch.LastBlock)
tx, err := ic.AcceptClaim(cb.txOpts, application.IApplicationAddress,
tx, err := ic.AcceptClaim(txOpts, application.IApplicationAddress,
lastBlockNumber, *epoch.MachineHash)
if err != nil {
cb.logger.Warn("acceptClaimOnBlockchain:failed",
Expand Down
2 changes: 2 additions & 0 deletions internal/claimer/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func (m *claimerBlockchainMock) findClaimAcceptedEventAndSucc(
}

func (m *claimerBlockchainMock) submitClaimToBlockchain(
ctx context.Context,
instance *iconsensus.IConsensus,
app *model.Application,
epoch *model.Epoch,
Expand All @@ -306,6 +307,7 @@ func (m *claimerBlockchainMock) submitClaimToBlockchain(
}

func (m *claimerBlockchainMock) acceptClaimOnBlockchain(
ctx context.Context,
app *model.Application,
epoch *model.Epoch,
) (common.Hash, error) {
Expand Down
14 changes: 7 additions & 7 deletions internal/claimer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/cartesi/rollups-node/internal/config/auth"
"github.com/cartesi/rollups-node/internal/model"
"github.com/cartesi/rollups-node/internal/repository"
"github.com/cartesi/rollups-node/pkg/ethutil"
"github.com/cartesi/rollups-node/pkg/service"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/ethclient"
)

Expand Down Expand Up @@ -126,20 +126,20 @@ func Create(ctx context.Context, c *CreateInfo) (*Service, error) {
s.maxAcceptAttempts = defaultMaxAcceptAttempts
}

var txOpts *bind.TransactOpts = nil
var txOptsFactory ethutil.TransactOptsFactory
if s.submissionEnabled {
txOpts, err = auth.GetTransactOpts(ctx, chainId)
txOptsFactory, err = auth.GetTransactOptsFactory(ctx, chainId)
if err != nil {
return nil, fmt.Errorf("getting transaction options: %w", err)
}
}

s.repository = c.Repository
s.blockchain = &claimerBlockchain{
logger: s.Logger,
client: c.EthConn,
txOpts: txOpts,
defaultBlock: nodeConfig.DefaultBlock,
logger: s.Logger,
client: c.EthConn,
txOptsFactory: txOptsFactory,
defaultBlock: nodeConfig.DefaultBlock,
}

return s, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/claimer/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (s *Service) broadcastComputedClaim(
"outputs_merkle_root", hashToHex(currEpoch.OutputsMerkleRoot),
"last_block", currEpoch.LastBlock,
)
txHash, err := s.blockchain.submitClaimToBlockchain(ic, app, currEpoch)
txHash, err := s.blockchain.submitClaimToBlockchain(s.Context, ic, app, currEpoch)
if err != nil {
switch outcome, stateErr := s.handleSubmitClaimRevert(err, app, currEpoch); outcome {
case submitClaimAlreadyOnChain:
Expand Down
Loading