Skip to content

Commit

Permalink
Hotfix Synchronization (0xPolygonHermez#1425)
Browse files Browse the repository at this point in the history
* hotfix

* Update state.go

Remove commented code

* log instead of remove sanity check
  • Loading branch information
ToniRamirezM authored Nov 29, 2022
1 parent 853ecdd commit d94aef5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions state/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func isProcessed(err pb.Error) bool {
return err != pb.Error_ERROR_INTRINSIC_INVALID_TX && err != pb.Error_ERROR_OUT_OF_COUNTERS
}

func isOOC(err pb.Error) bool {
return err == pb.Error_ERROR_OUT_OF_COUNTERS
}

func convertToProcessTransactionResponse(txs []types.Transaction, responses []*pb.ProcessTransactionResponse) ([]*ProcessTransactionResponse, error) {
results := make([]*ProcessTransactionResponse, 0, len(responses))
for i, response := range responses {
Expand Down
18 changes: 13 additions & 5 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,18 @@ func (s *State) ProcessAndStoreClosedBatch(ctx context.Context, processingCtx Pr

// Sanity check
if len(decodedTransactions) != len(processed.Responses) {
return fmt.Errorf("number of decoded (%d) and processed (%d) transactions do not match", len(decodedTransactions), len(processed.Responses))
log.Errorf("number of decoded (%d) and processed (%d) transactions do not match", len(decodedTransactions), len(processed.Responses))
}

// Filter unprocessed txs and decode txs to store metadata
// note that if the batch is not well encoded it will result in an empty batch (with no txs)
for i := 0; i < len(processed.Responses); i++ {
if !isProcessed(processed.Responses[i].Error) {
if isOOC(processed.Responses[i].Error) {
processed.Responses = []*pb.ProcessTransactionResponse{}
break
}

// Remove unprocessed tx
if i == len(processed.Responses)-1 {
processed.Responses = processed.Responses[:i]
Expand All @@ -719,10 +724,13 @@ func (s *State) ProcessAndStoreClosedBatch(ctx context.Context, processingCtx Pr
if err != nil {
return err
}
// Store processed txs into the batch
err = s.StoreTransactions(ctx, processingCtx.BatchNumber, processedBatch.Responses, dbTx)
if err != nil {
return err

if len(processedBatch.Responses) > 0 {
// Store processed txs into the batch
err = s.StoreTransactions(ctx, processingCtx.BatchNumber, processedBatch.Responses, dbTx)
if err != nil {
return err
}
}

// Close batch
Expand Down

0 comments on commit d94aef5

Please sign in to comment.