Skip to content
Closed
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
12 changes: 6 additions & 6 deletions cmd/cartesi-rollups-cli/root/deploy/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ const applicationExamples = `

func init() {
applicationCmd.Flags().StringVarP(&applicationConsensusAddressParam, "consensus", "c", "",
"Consensus Address")
"Consensus address. A new authority consensus will be created if this field is left empty.")
applicationCmd.Flags().StringVarP(&applicationFactoryAddressParam, "factory", "f", "",
"Factory Address")
"Application factory address. Default value is retrieved from configuration.")
applicationCmd.Flags().StringVarP(&applicationOwnerAddressParam, "owner", "o", "",
"Owner Address")
"Application owner address. If not defined, it will be derived from the auth method.")
applicationCmd.Flags().StringVarP(&applicationDataAvailabilityParam, "data-availability", "d", "",
"Owner Address")
"Data availability string. Default is input box.")
applicationCmd.Flags().BoolVarP(&applicationSelfHostedParam, "self-hosted", "s", false,
"Self Hosted Application")
"Self Hosted Application. Request the application to be deployed as self hosted.")
applicationCmd.Flags().StringVarP(&applicationTemplateHashParam, "template-hash", "H", "",
"Template hash. If not provided, it will be read from the template path")
applicationCmd.Flags().BoolVarP(&applicationRegisterParam, "register", "r", true,
"Register the application into the database")
applicationCmd.Flags().BoolVarP(&applicationEnableParam, "enable", "e", true,
"Application Owner Address. If not defined, it will be derived from the auth method.")
"Start processing the application, requires 'register=true'.")

// in case the user also requests an authority deployment
applicationCmd.Flags().StringVarP(&authorityFactoryAddressParam, "authority-factory", "F", "",
Expand Down
4 changes: 2 additions & 2 deletions cmd/cartesi-rollups-cli/root/read/reports/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func init() {

Cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if limit > jsonrpc.LIST_ITEM_LIMIT {
return fmt.Errorf("limit cannot exceed %d", jsonrpc.LIST_ITEM_LIMIT)
return fmt.Errorf("[init]: limit cannot exceed %d", jsonrpc.LIST_ITEM_LIMIT)
} else if limit == 0 {
limit = jsonrpc.LIST_ITEM_LIMIT
}
Expand All @@ -91,7 +91,7 @@ func run(cmd *cobra.Command, args []string) {
// Get a specific report by index
reportIndex, err := config.ToUint64FromDecimalOrHexString(args[1])
if err != nil {
cobra.CheckErr(fmt.Errorf("invalid report index value: %w", err))
cobra.CheckErr(fmt.Errorf("[run]: invalid report index value: %w", err))
}

report, err := repo.GetReport(ctx, nameOrAddress, reportIndex)
Expand Down
32 changes: 20 additions & 12 deletions internal/claimer/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ type claimerBlockchain struct {
defaultBlock config.DefaultBlock
}

func (self *claimerBlockchain) submitClaimToBlockchain(
func (cb *claimerBlockchain) submitClaimToBlockchain(
ic *iconsensus.IConsensus,
application *model.Application,
epoch *model.Epoch,
) (common.Hash, error) {
txHash := common.Hash{}
lastBlockNumber := new(big.Int).SetUint64(epoch.LastBlock)
tx, err := ic.SubmitClaim(self.txOpts, application.IApplicationAddress,
tx, err := ic.SubmitClaim(cb.txOpts, application.IApplicationAddress,
lastBlockNumber, *epoch.ClaimHash)
if err != nil {
self.logger.Error("submitClaimToBlockchain:failed",
cb.logger.Error("submitClaimToBlockchain:failed",
"appContractAddress", application.IApplicationAddress,
"claimHash", *epoch.ClaimHash,
"last_block", epoch.LastBlock,
"error", err)
} else {
txHash = tx.Hash()
self.logger.Debug("submitClaimToBlockchain:success",
cb.logger.Debug("submitClaimToBlockchain:success",
"appContractAddress", application.IApplicationAddress,
"claimHash", *epoch.ClaimHash,
"last_block", epoch.LastBlock,
Expand All @@ -121,7 +121,7 @@ func unwrapClaimSubmitted(

// scan the event stream for a claimSubmitted event that matches claim.
// return this event and its successor
func (self *claimerBlockchain) findClaimSubmittedEventAndSucc(
func (cb *claimerBlockchain) findClaimSubmittedEventAndSucc(
ctx context.Context,
application *model.Application,
epoch *model.Epoch,
Expand All @@ -132,7 +132,7 @@ func (self *claimerBlockchain) findClaimSubmittedEventAndSucc(
*iconsensus.IConsensusClaimSubmitted,
error,
) {
ic, err := iconsensus.NewIConsensus(application.IConsensusAddress, self.client)
ic, err := iconsensus.NewIConsensus(application.IConsensusAddress, cb.client)
if err != nil {
return nil, nil, nil, err
}
Expand All @@ -142,23 +142,26 @@ func (self *claimerBlockchain) findClaimSubmittedEventAndSucc(
// - submitter == nil (any)
// - appContract == claim.IApplicationAddress
c, err := iconsensus.IConsensusMetaData.GetAbi()
if err != nil {
return nil, nil, nil, fmt.Errorf("[findClaimSubmittedEventAndSucc]: failed to get IConsensusMetaData ABI: %w", err)
}
topics, err := abi.MakeTopics(
[]any{c.Events[model.MonitoredEvent_ClaimSubmitted.String()].ID},
nil,
[]any{application.IApplicationAddress},
)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, fmt.Errorf("[findClaimSubmittedEventAndSucc]: failed make topics: %w", err)
}

it, err := self.filter.ChunkedFilterLogs(ctx, self.client, ethereum.FilterQuery{
it, err := cb.filter.ChunkedFilterLogs(ctx, cb.client, ethereum.FilterQuery{
FromBlock: new(big.Int).SetUint64(epoch.LastBlock),
ToBlock: endBlock,
Addresses: []common.Address{application.IConsensusAddress},
Topics: topics,
})
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, fmt.Errorf("[findClaimSubmittedEventAndSucc]: failed to filter logs: %w", err)
}

// pull events instead of iterating
Expand All @@ -175,11 +178,12 @@ func (self *claimerBlockchain) findClaimSubmittedEventAndSucc(
// found the event, does it has a successor? try to fetch it
succ, ok, err := unwrapClaimSubmitted(ic, next)
if !ok || err != nil {
err = fmt.Errorf("[findClaimSubmittedEventAndSucc]: failed to unwrap ClaimSubmitted event: %w", err)
return ic, event, nil, err
}
return ic, event, succ, err
} else if lastBlock > epoch.LastBlock {
err = fmt.Errorf("No matching claim, searched up to %v", event)
err = fmt.Errorf("[findClaimSubmittedEventAndSucc]: No matching claim, last searched event was: %v", event)
return nil, nil, nil, err
}
}
Expand Down Expand Up @@ -223,6 +227,9 @@ func (self *claimerBlockchain) findClaimAcceptedEventAndSucc(
// - `ClaimAccepted` events
// - appContract == claim.IApplicationAddress
c, err := iconsensus.IConsensusMetaData.GetAbi()
if err != nil {
return nil, nil, nil, fmt.Errorf("[findClaimAcceptedEventAndSucc]: failed to get IConsensusMetaData ABI: %w", err)
}
topics, err := abi.MakeTopics(
[]any{c.Events[model.MonitoredEvent_ClaimAccepted.String()].ID},
[]any{application.IApplicationAddress},
Expand Down Expand Up @@ -255,11 +262,12 @@ func (self *claimerBlockchain) findClaimAcceptedEventAndSucc(
// found the event, does it has a successor? try to fetch it
succ, ok, err := unwrapClaimAccepted(ic, next)
if !ok || err != nil {
err = fmt.Errorf("[findClaimAcceptedEventAndSucc]: failed to unwrap ClaimAccepted event: %w", err)
return ic, event, nil, err
}
return ic, event, succ, err
} else if lastBlock > epoch.LastBlock {
err = fmt.Errorf("No matching claim, searched up to %v", event)
err = fmt.Errorf("[findClaimAcceptedEventAndSucc]: no matching claim, searched up to %v", event)
return nil, nil, nil, err
}
}
Expand Down Expand Up @@ -308,7 +316,7 @@ func (self *claimerBlockchain) getBlockNumber(ctx context.Context) (*big.Int, er
case model.DefaultBlock_Safe:
nr = rpc.SafeBlockNumber.Int64()
default:
return nil, fmt.Errorf("default block '%v' not supported", self.defaultBlock)
return nil, fmt.Errorf("[getBlockNumber]: default block '%v' not supported", self.defaultBlock)
}

hdr, err := self.client.HeaderByNumber(ctx, big.NewInt(nr))
Expand Down
19 changes: 11 additions & 8 deletions internal/claimer/claimer.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,16 @@ func (s *Service) checkConsensusForAddressChange(

func checkEpochConstraint(c *model.Epoch) error {
if c.FirstBlock > c.LastBlock {
return fmt.Errorf("unexpected epoch state. first_block: %v > last_block: %v", c.FirstBlock, c.LastBlock)
return fmt.Errorf("[checkEpochConstraint]: unexpected epoch state. first_block: %v > last_block: %v", c.FirstBlock, c.LastBlock)
}
if c.Status == model.EpochStatus_ClaimSubmitted {
if c.ClaimHash == nil {
return fmt.Errorf("unexpected epoch state. missing claim_hash.")
return fmt.Errorf("[checkEpochConstraint]: unexpected epoch state. missing claim_hash")
}
}
if c.Status == model.EpochStatus_ClaimAccepted || c.Status == model.EpochStatus_ClaimSubmitted {
if c.ClaimTransactionHash == nil {
return fmt.Errorf("unexpected epoch state. missing claim_transaction_hash.")
return fmt.Errorf("[checkEpochConstraint]: unexpected epoch state. missing claim_transaction_hash")
}
}
return nil
Expand All @@ -502,21 +502,24 @@ func checkEpochSequenceConstraint(prevEpoch *model.Epoch, currEpoch *model.Epoch

err = checkEpochConstraint(currEpoch)
if err != nil {
return fmt.Errorf("%w on current epoch.", err)
return fmt.Errorf("[checkEpochSequenceConstraint]: %w on current epoch", err)
}
err = checkEpochConstraint(prevEpoch)
if err != nil {
return fmt.Errorf("%w on previous epoch.", err)
return fmt.Errorf("[checkEpochSequenceConstraint]: %w on previous epoch", err)
}

if prevEpoch.LastBlock > currEpoch.LastBlock {
return fmt.Errorf("unexpected epochs sequence on field last_block: previous(%v) > current(%v)", prevEpoch.LastBlock, currEpoch.LastBlock)
return fmt.Errorf("[checkEpochSequenceConstraint]: unexpected field last_block: previous(%v) > current(%v)",
prevEpoch.LastBlock, currEpoch.LastBlock)
}
if prevEpoch.FirstBlock > currEpoch.FirstBlock {
return fmt.Errorf("unexpected epochs sequence on field first_block: previous(%v) > current(%v)", prevEpoch.FirstBlock, currEpoch.FirstBlock)
return fmt.Errorf("[checkEpochSequenceConstraint]: unexpected field first_block: previous(%v) > current(%v)",
prevEpoch.FirstBlock, currEpoch.FirstBlock)
}
if prevEpoch.Index > currEpoch.Index {
return fmt.Errorf("unexpected epochs sequence on field index: previous(%v) > current(%v)", prevEpoch.Index, currEpoch.Index)
return fmt.Errorf("[checkEpochSequenceConstraint]: unexpected field index: previous(%v) > current(%v)",
prevEpoch.Index, currEpoch.Index)
}
return nil
}
Expand Down
13 changes: 6 additions & 7 deletions internal/claimer/claimer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/cartesi/rollups-node/internal/model"
. "github.com/cartesi/rollups-node/internal/model"
"github.com/cartesi/rollups-node/internal/repository"
"github.com/cartesi/rollups-node/pkg/contracts/iconsensus"
"github.com/cartesi/rollups-node/pkg/service"
Expand All @@ -34,9 +33,9 @@ func (m *claimerRepositoryMock) ListApplications(
ctx context.Context,
f repository.ApplicationFilter,
pagination repository.Pagination,
) ([]*Application, uint64, error) {
) ([]*model.Application, uint64, error) {
args := m.Called(ctx, f, pagination)
return args.Get(0).([]*Application), args.Get(1).(uint64), args.Error(2)
return args.Get(0).([]*model.Application), args.Get(1).(uint64), args.Error(2)
}

func (m *claimerRepositoryMock) SelectSubmittedClaimPairsPerApp(ctx context.Context) (
Expand Down Expand Up @@ -77,7 +76,7 @@ func (m *claimerRepositoryMock) UpdateEpochWithSubmittedClaim(
func (m *claimerRepositoryMock) UpdateApplicationState(
ctx context.Context,
appID int64,
state ApplicationState,
state model.ApplicationState,
reason *string,
) error {
args := m.Called(ctx, appID, state, reason)
Expand Down Expand Up @@ -219,7 +218,7 @@ func makeApplication(id int64) *model.Application {
func makeEpoch(id int64, status model.EpochStatus, i uint64) *model.Epoch {
hash := common.HexToHash("0x01")
tx := common.HexToHash("0x02")
epoch := &Epoch{
epoch := &model.Epoch{
ApplicationID: id,
Index: i,
FirstBlock: i * 10,
Expand All @@ -243,14 +242,14 @@ func makeComputedEpoch(app *model.Application, i uint64) *model.Epoch {
return makeEpoch(app.ID, model.EpochStatus_ClaimComputed, i)
}
func makeEpochMap(epochs ...*model.Epoch) map[int64]*model.Epoch {
result := map[int64]*Epoch{}
result := map[int64]*model.Epoch{}
for _, epoch := range epochs {
result[epoch.ApplicationID] = epoch
}
return result
}
func makeApplicationMap(apps ...*model.Application) map[int64]*model.Application {
result := map[int64]*Application{}
result := map[int64]*model.Application{}
for _, app := range apps {
result[app.ID] = app
}
Expand Down
3 changes: 2 additions & 1 deletion internal/evmreader/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ func (r *Service) readAndStoreInputs(
)
err := r.repository.UpdateApplicationState(ctx, app.application.ID, ApplicationState_Inoperable, &reason)
if err != nil {
r.Logger.Error("failed to update application state to inoperable", "application", app.application.Name, "err", err)
r.Logger.Error("failed to update application state to inoperable", "application",
app.application.Name, "err", err)
}
return errors.New(reason)
}
Expand Down
18 changes: 9 additions & 9 deletions internal/merkle/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,21 @@ func ComputeSiblingsMatrix(
post []common.Hash,
outputsBegin uint64,
) ([]common.Hash, error) {
if outputHashes == nil || len(outputHashes) == 0 {
return nil, fmt.Errorf("incorrect outputHashes in call ComputeSiblingsMatrix.")
if len(outputHashes) == 0 {
return nil, fmt.Errorf("[ComputeSiblingsMatrix]: incorrect outputHashes")
}
if pre == nil || len(pre) == 0 {
return nil, fmt.Errorf("incorrect pre context in call ComputeSiblingsMatrix.")
if len(pre) == 0 {
return nil, fmt.Errorf("[ComputeSiblingsMatrix]: incorrect pre context")
}
if post == nil || len(post) == 0 {
return nil, fmt.Errorf("incorrect post context in call ComputeSiblingsMatrix.")
if len(post) == 0 {
return nil, fmt.Errorf("[ComputeSiblingsMatrix]: incorrect post context")
}

hashes := dupArray(outputHashes) // preserve input
siblings := make([]common.Hash, len(hashes)*TREE_DEPTH)
childrenBegin := outputsBegin
childrenEnd := outputsBegin + uint64(len(hashes))
for level := 0; level < TREE_DEPTH; level++ {
for level := range TREE_DEPTH {
children := arrayChunk{
hashes: hashes,
before: &pre[level],
Expand All @@ -139,7 +139,7 @@ func ComputeSiblingsMatrix(
}

// store siblings
for i := 0; i < len(hashes); i++ {
for i := range hashes {
sibling := ((outputsBegin + uint64(i)) >> level) ^ 1
siblings[i*TREE_DEPTH+level] = *children.get(sibling)
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func CreateProofs(leaves []common.Hash, height uint) (common.Hash, []common.Hash
siblings := make([]common.Hash, leafCount*height)

// for each level in the tree, starting from the leaves
for levelIdx := uint(0); levelIdx < height; levelIdx++ {
for levelIdx := range height {
// for each leaf
for leafIdx := uint(0); leafIdx < leafCount; leafIdx++ {
// calculate its sibling at the current level
Expand Down
4 changes: 3 additions & 1 deletion internal/merkle/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func TestIncorrectCreateProofsLevel(t *testing.T) {

func TestComputSiblingsMatrixAssertions(t *testing.T) {
var err error
outputs := []common.Hash{common.Hash{}}
outputs := []common.Hash{
{},
}
post := CreatePostContext() // always the same
pre := post
index := uint64(0)
Expand Down
4 changes: 2 additions & 2 deletions internal/repository/postgres/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type Schema struct {
}

var (
ErrMigrationNotCompleted = errors.New("Schema version is dirty")
ErrNoValidDatabaseSchema = errors.New("No valid database schema found")
ErrMigrationNotCompleted = errors.New("schema version is dirty")
ErrNoValidDatabaseSchema = errors.New("no valid database schema found")
)

func New(postgresEndpoint string) (*Schema, error) {
Expand Down
Loading
Loading