Skip to content

Commit

Permalink
Fix: sr_execute_outbox_message
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Aug 17, 2023
1 parent e2e6e22 commit 1c8bbba
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 45 deletions.
24 changes: 15 additions & 9 deletions cmd/api/handlers/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]),
},
},
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions configs/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions configs/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/bcd/literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func IsOperationHash(str string) bool {
return operationRegex.MatchString(str)
}

// IsOperationHash -
// IsSmartRollupHash -
func IsSmartRollupHash(str string) bool {
return smartRollupRegex.MatchString(str)
}
4 changes: 4 additions & 0 deletions internal/bcd/literal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
46 changes: 25 additions & 21 deletions internal/noderpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package noderpc
import (
"bytes"
"context"
stdJSON "encoding/json"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 -
Expand Down
4 changes: 2 additions & 2 deletions internal/parsers/operations/operation_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions internal/parsers/operations/sr_execute_outbox_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1c8bbba

Please sign in to comment.