Skip to content

Commit

Permalink
Fix rpc pending blocks (#981)
Browse files Browse the repository at this point in the history
Remove pending block from validation. Check for nilpointer
  • Loading branch information
cabrador authored Feb 9, 2024
1 parent e4271c9 commit e75035f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
4 changes: 3 additions & 1 deletion executor/extension/statedb/temporary_archive_prepper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type temporaryArchivePrepper struct {

// PreTransaction creates temporary archive that is released after transaction is executed.
func (r *temporaryArchivePrepper) PreTransaction(state executor.State[*rpc.RequestAndResults], ctx *executor.Context) error {
block := findBlockNumber(state.Data) // save the block for progress tracker
block := findBlockNumber(state.Data)

var err error
ctx.Archive, err = ctx.State.GetArchiveState(block)
Expand Down Expand Up @@ -54,6 +54,8 @@ func findBlockNumber(data *rpc.RequestAndResults) uint64 {

switch str {
case "pending":
// validation for pending requests does not work, skip them
data.SkipValidation = true
// pending should be treated as latest
fallthrough
case "latest":
Expand Down
43 changes: 43 additions & 0 deletions executor/extension/statedb/temporary_archive_prepper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package statedb

import (
"encoding/json"
"testing"

"github.com/Fantom-foundation/Aida/executor"
"github.com/Fantom-foundation/Aida/rpc"
"github.com/Fantom-foundation/Aida/state"
"go.uber.org/mock/gomock"
)

func TestTemporaryArchivePrepper_PreTransactionMarksPendingBlockAsSkipValidation(t *testing.T) {
ctrl := gomock.NewController(t)
db := state.NewMockStateDB(ctrl)
ext := MakeTemporaryArchivePrepper()

db.EXPECT().GetArchiveState(uint64(10)).Return(nil, nil)

st := executor.State[*rpc.RequestAndResults]{Block: 10, Transaction: 0, Data: data}
ctx := &executor.Context{State: db}
err := ext.PreTransaction(st, ctx)
if err != nil {
t.Fatal(err)
}

if !data.SkipValidation {
t.Fatal("SkipValidation must be true")
}
}

var data = &rpc.RequestAndResults{
Query: &rpc.Body{
Params: []interface{}{"test", "pending"},
},
Response: &rpc.Response{
Version: "2.0",
ID: json.RawMessage{1},
BlockID: 10,
Timestamp: 10,
},
SkipValidation: false,
}
5 changes: 5 additions & 0 deletions executor/extension/validator/rpc_comparator.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ type rpcComparator struct {
func (c *rpcComparator) PostTransaction(state executor.State[*rpc.RequestAndResults], ctx *executor.Context) error {
c.totalNumberOfRequests++

// pending block numbers are not validatable
if state.Data.SkipValidation || state.Data.StateDB == nil {
return nil
}

compareErr := compare(state)
if compareErr != nil {
// lot errors are recorded wrongly, for this case we resend the request and compare it again
Expand Down
13 changes: 7 additions & 6 deletions rpc/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import "encoding/json"

// RequestAndResults encapsulates request query and response for post-processing.
type RequestAndResults struct {
Query *Body
Response *Response
Error *ErrorResponse
ParamsRaw []byte
ResponseRaw []byte
StateDB *StateDBData
Query *Body
Response *Response
Error *ErrorResponse
ParamsRaw []byte
ResponseRaw []byte
StateDB *StateDBData
SkipValidation bool
}

// Body represents a decoded payload of a balancer.
Expand Down

0 comments on commit e75035f

Please sign in to comment.