From 1c8bbba704009642555451e87f9333efe93b0632 Mon Sep 17 00:00:00 2001 From: Artem Date: Thu, 17 Aug 2023 16:41:16 +0400 Subject: [PATCH] Fix: sr_execute_outbox_message --- cmd/api/handlers/operations.go | 24 ++++++---- configs/development.yml | 10 ++-- configs/production.yml | 10 ++-- internal/bcd/literal.go | 2 +- internal/bcd/literal_test.go | 4 ++ internal/noderpc/rpc.go | 46 ++++++++++--------- .../parsers/operations/operation_group.go | 4 +- .../operations/sr_execute_outbox_message.go | 4 +- 8 files changed, 59 insertions(+), 45 deletions(-) diff --git a/cmd/api/handlers/operations.go b/cmd/api/handlers/operations.go index 9349fd20b..11657d137 100644 --- a/cmd/api/handlers/operations.go +++ b/cmd/api/handlers/operations.go @@ -526,15 +526,21 @@ func prepareOperation(ctx *config.Context, operation operation.Operation, bmd [] } op.Payload = []*ast.MiguelNode{ { - Prim: "string", - Type: "string", - Name: getStringPointer("cemented_commitment"), - Value: commitment, - }, { - Prim: "bytes", - Type: "bytes", - Name: getStringPointer("output_proof"), - Value: hex.EncodeToString(operation.Payload[32:]), + Prim: "pair", + Type: "namedtuple", + Children: []*ast.MiguelNode{ + { + Prim: "string", + Type: "string", + Name: getStringPointer("cemented_commitment"), + Value: commitment, + }, { + Prim: "bytes", + Type: "bytes", + Name: getStringPointer("output_proof"), + Value: hex.EncodeToString(operation.Payload[32:]), + }, + }, }, } } diff --git a/configs/development.yml b/configs/development.yml index fc7d0c049..0bd948ddb 100644 --- a/configs/development.yml +++ b/configs/development.yml @@ -6,11 +6,11 @@ rpc: ghostnet: uri: https://rpc.tzkt.io/ghostnet timeout: 20 - requests_per_second: 10 + requests_per_second: 15 nairobinet: uri: https://rpc.tzkt.io/nairobinet timeout: 20 - requests_per_second: 20 + requests_per_second: 15 tzkt: mainnet: @@ -73,11 +73,11 @@ indexer: sentry_enabled: false networks: mainnet: - receiver_threads: 5 + receiver_threads: 15 ghostnet: - receiver_threads: 10 + receiver_threads: 15 nairobinet: - receiver_threads: 10 + receiver_threads: 15 connections: max: 5 idle: 5 diff --git a/configs/production.yml b/configs/production.yml index f92aa5f3d..f02601ddf 100644 --- a/configs/production.yml +++ b/configs/production.yml @@ -6,11 +6,11 @@ rpc: ghostnet: uri: https://rpc.tzkt.io/ghostnet timeout: 20 - requests_per_second: 10 + requests_per_second: 15 nairobinet: uri: https://rpc.tzkt.io/nairobinet timeout: 20 - requests_per_second: 20 + requests_per_second: 15 tzkt: mainnet: @@ -74,11 +74,11 @@ indexer: sentry_enabled: true networks: mainnet: - receiver_threads: ${MAINNET_THREADS:-1} + receiver_threads: ${MAINNET_THREADS:-10} ghostnet: - receiver_threads: ${TESTNET_THREADS:-1} + receiver_threads: ${TESTNET_THREADS:-10} nairobinet: - receiver_threads: ${TESTNET_THREADS:-1} + receiver_threads: ${TESTNET_THREADS:-10} connections: max: 5 idle: 5 diff --git a/internal/bcd/literal.go b/internal/bcd/literal.go index 236f7b1fc..02dfd336d 100644 --- a/internal/bcd/literal.go +++ b/internal/bcd/literal.go @@ -70,7 +70,7 @@ func IsOperationHash(str string) bool { return operationRegex.MatchString(str) } -// IsOperationHash - +// IsSmartRollupHash - func IsSmartRollupHash(str string) bool { return smartRollupRegex.MatchString(str) } diff --git a/internal/bcd/literal_test.go b/internal/bcd/literal_test.go index c9056f70e..05d3d9457 100644 --- a/internal/bcd/literal_test.go +++ b/internal/bcd/literal_test.go @@ -59,6 +59,10 @@ func TestIsAddress(t *testing.T) { name: "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UA", address: "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UA", want: false, + }, { + name: "sr1J1ECygUgzE7urU3Ayr5HZaty83hpjbs28", + address: "sr1J1ECygUgzE7urU3Ayr5HZaty83hpjbs28", + want: true, }, } for _, tt := range tests { diff --git a/internal/noderpc/rpc.go b/internal/noderpc/rpc.go index a924d3515..d15d279c3 100644 --- a/internal/noderpc/rpc.go +++ b/internal/noderpc/rpc.go @@ -3,7 +3,6 @@ package noderpc import ( "bytes" "context" - stdJSON "encoding/json" "fmt" "io" "net/http" @@ -60,10 +59,9 @@ func NewNodeRPC(baseURL string, opts ...NodeOption) *NodeRPC { } t := http.DefaultTransport.(*http.Transport).Clone() - t.MaxIdleConns = 100 - t.MaxConnsPerHost = 100 - t.MaxIdleConnsPerHost = 100 - + t.MaxIdleConns = 20 + t.MaxConnsPerHost = 20 + t.MaxIdleConnsPerHost = 20 node.client = &http.Client{ Timeout: node.timeout, Transport: t, @@ -87,15 +85,15 @@ func NewWaitNodeRPC(baseURL string, opts ...NodeOption) *NodeRPC { return node } -func (rpc *NodeRPC) checkStatusCode(resp *http.Response, checkStatusCode bool) error { +func (rpc *NodeRPC) checkStatusCode(r io.Reader, statusCode int, checkStatusCode bool) error { switch { - case resp.StatusCode == http.StatusOK: + case statusCode == http.StatusOK: return nil - case resp.StatusCode > http.StatusInternalServerError: - return NewNodeUnavailiableError(rpc.baseURL, resp.StatusCode) + case statusCode > http.StatusInternalServerError: + return NewNodeUnavailiableError(rpc.baseURL, statusCode) case checkStatusCode: invalidResponseErr := newInvalidNodeResponse() - data, err := io.ReadAll(resp.Body) + data, err := io.ReadAll(r) if err != nil { return err } @@ -109,12 +107,12 @@ func (rpc *NodeRPC) checkStatusCode(resp *http.Response, checkStatusCode bool) e } } -func (rpc *NodeRPC) parseResponse(resp *http.Response, checkStatusCode bool, uri string, response interface{}) error { - if err := rpc.checkStatusCode(resp, checkStatusCode); err != nil { +func (rpc *NodeRPC) parseResponse(r io.Reader, statusCode int, checkStatusCode bool, uri string, response interface{}) error { + if err := rpc.checkStatusCode(r, statusCode, checkStatusCode); err != nil { return fmt.Errorf("%w (%s): %w", ErrNodeRPCError, uri, err) } - return json.NewDecoder(resp.Body).Decode(response) + return json.NewDecoder(r).Decode(response) } func (rpc *NodeRPC) makeRequest(ctx context.Context, req *http.Request) (*http.Response, error) { @@ -166,7 +164,12 @@ func (rpc *NodeRPC) get(ctx context.Context, uri string, response interface{}) e } defer resp.Body.Close() - return rpc.parseResponse(resp, true, uri, response) + buffer := new(bytes.Buffer) + if _, err = io.Copy(buffer, resp.Body); err != nil { + return err + } + + return rpc.parseResponse(buffer, resp.StatusCode, true, uri, response) } func (rpc *NodeRPC) getRaw(ctx context.Context, uri string) ([]byte, error) { @@ -189,7 +192,7 @@ func (rpc *NodeRPC) getRaw(ctx context.Context, uri string) ([]byte, error) { } defer resp.Body.Close() - if err := rpc.checkStatusCode(resp, true); err != nil { + if err := rpc.checkStatusCode(resp.Body, resp.StatusCode, true); err != nil { return nil, fmt.Errorf("%w (%s): %w", ErrNodeRPCError, uri, err) } return io.ReadAll(resp.Body) @@ -215,7 +218,12 @@ func (rpc *NodeRPC) post(ctx context.Context, uri string, data interface{}, chec } defer resp.Body.Close() - return rpc.parseResponse(resp, checkStatusCode, uri, response) + buffer := new(bytes.Buffer) + if _, err = io.Copy(buffer, resp.Body); err != nil { + return err + } + + return rpc.parseResponse(buffer, resp.StatusCode, checkStatusCode, uri, response) } // Block - returns block @@ -259,11 +267,7 @@ func (rpc *NodeRPC) GetRawScript(ctx context.Context, address string, level int6 // GetScriptStorageRaw - func (rpc *NodeRPC) GetScriptStorageRaw(ctx context.Context, address string, level int64) ([]byte, error) { - var response struct { - Storage stdJSON.RawMessage `json:"storage"` - } - err := rpc.get(ctx, fmt.Sprintf("chains/main/blocks/%s/context/contracts/%s/script", getBlockString(level), address), &response) - return response.Storage, err + return rpc.getRaw(ctx, fmt.Sprintf("chains/main/blocks/%s/context/contracts/%s/storage", getBlockString(level), address)) } // GetContractBalance - diff --git a/internal/parsers/operations/operation_group.go b/internal/parsers/operations/operation_group.go index e3e678aa5..4dc17682f 100644 --- a/internal/parsers/operations/operation_group.go +++ b/internal/parsers/operations/operation_group.go @@ -68,8 +68,8 @@ func (Group) needParse(item noderpc.LightOperation) bool { registerGlobalConstantCondition := item.Kind == consts.RegisterGlobalConstant eventCondition := item.Kind == consts.Event transferTicketCondition := item.Kind == consts.TransferTicket - srOriginateCondition := item.Kind == consts.SrOriginate - return originationCondition || transactionCondition || srOriginateCondition || + srCondition := item.Kind == consts.SrOriginate || item.Kind == consts.SrExecuteOutboxMessage + return originationCondition || transactionCondition || srCondition || registerGlobalConstantCondition || eventCondition || transferTicketCondition } diff --git a/internal/parsers/operations/sr_execute_outbox_message.go b/internal/parsers/operations/sr_execute_outbox_message.go index 70731da0f..21583014c 100644 --- a/internal/parsers/operations/sr_execute_outbox_message.go +++ b/internal/parsers/operations/sr_execute_outbox_message.go @@ -60,13 +60,13 @@ func (p SrExecuteOutboxMessage) Parse(data noderpc.Operation, store parsers.Stor if err != nil { return errors.Wrap(err, "cemented commitment decoding") } - data.Payload = append(data.Payload, commitment...) + operation.Payload = append(operation.Payload, commitment...) proof, err := hex.DecodeString(data.OutputProof) if err != nil { return errors.Wrap(err, "outbox proof decoding") } - data.Payload = append(data.Payload, proof...) + operation.Payload = append(operation.Payload, proof...) } store.AddOperations(&operation)