Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: RPC HTTP Batch doesn't support 1 item responses #3676

Closed
zivkovicmilos opened this issue Feb 3, 2025 · 1 comment · Fixed by #3678
Closed

bug: RPC HTTP Batch doesn't support 1 item responses #3676

zivkovicmilos opened this issue Feb 3, 2025 · 1 comment · Fixed by #3678
Assignees
Labels
🐞 bug Something isn't working help wanted Want to contribute? We recommend these issues.

Comments

@zivkovicmilos
Copy link
Member

zivkovicmilos commented Feb 3, 2025

RPC HTTP Batch doesn't support 1 item responses

Description

When sending an HTTP RPC batch, with a single item in the batch, the Send fails with the following message:
unable to send RPC batch, unable to unmarshal response body, json: cannot unmarshal object into Go value of type rpctypes.RPCResponses

Your environment

  • Go version - go version go1.23.5 darwin/arm64
  • OS and CPU architecture - macOS 15.2
  • Gno commit hash causing the issue - 815cf51273a20cd7752c72d5903b02d373584a65 (master)

Steps to reproduce

Run a local gno node with --lazy, and run this Go script:

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
	core_types "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types"
)

func main() {
	c, err := client.NewHTTPClient("http://127.0.0.1:26657")
	if err != nil {
		panic(err)
	}

	// Create the batch
	b := c.NewBatch()

	if err = b.Status(); err != nil {
		panic(err)
	}

	// Send the batch
	ctx, cancelFn := context.WithTimeout(context.Background(), time.Second*10)
	defer cancelFn()

	resp, err := b.Send(ctx)
	if err != nil {
		panic(err)
	}

	// Parse the response
	for i, resultRaw := range resp {
		result, ok := resultRaw.(*core_types.ResultStatus)
		if !ok {
			panic("unable to cast batch result into ResultStatus")
		}

		fmt.Printf("Status %d: %v\n", i, result)
	}
}

Expected behavior

The single response should be wrapped in an RPCResponses type

Actual behavior

There is an error returned:

panic: unable to send RPC batch, unable to unmarshal response body, json: cannot unmarshal object into Go value of type rpctypes.RPCResponses

goroutine 1 [running]:
main.main()
        /Users/zmilos/Work/go-test/main.go:37 +0x290
exit status 2

Logs

unable to send RPC batch, unable to unmarshal response body, json: cannot unmarshal object into Go value of type rpctypes.RPCResponses

Proposed solution

If you have an idea of how to fix this issue, please write it down here, so we can begin discussing it

@zivkovicmilos zivkovicmilos added the 🐞 bug Something isn't working label Feb 3, 2025
@zivkovicmilos zivkovicmilos added the help wanted Want to contribute? We recommend these issues. label Feb 3, 2025
@zivkovicmilos
Copy link
Member Author

This issue is NOT present with a WS client, just the HTTP client:

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
	core_types "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types"
)

func main() {
	c, err := client.NewWSClient("ws://127.0.0.1:26657/websocket")
	if err != nil {
		panic(err)
	}

	// Create the batch
	b := c.NewBatch()

	if err = b.Status(); err != nil {
		panic(err)
	}

	// Send the batch
	ctx, cancelFn := context.WithTimeout(context.Background(), time.Second*10)
	defer cancelFn()

	resp, err := b.Send(ctx)
	if err != nil {
		panic(err)
	}

	// Parse the response
	for i, resultRaw := range resp {
		result, ok := resultRaw.(*core_types.ResultStatus)
		if !ok {
			panic("unable to cast batch result into ResultStatus")
		}

		fmt.Printf("Status %d: %v\n", i, result)
	}
}
Status 0: &{{[{abci v1.0.0-rc.0 false} {app  false} {bft v1.0.0-rc.0 false} {blockchain v1.0.0-rc.0 false} {p2p v1.0.0-rc.0 false}] g172gywwumzylyhn80m9mrrvh0akcp6jhw92n47v dev  v1.0.0-rc.0 [64 32 33 34 35 48 80] artemis.local {off tcp://127.0.0.1:26657}} {[150 174 227 166 228 10 169 83 202 110 246 135 173 150 7 208 83 175 101 144 85 164 22 104 19 31 62 42 169 179 19 51] [128 147 227 28 181 71 244 156 100 205 219 36 240 101 221 87 224 191 234 59 155 222 82 80 164 20 173 14 174 171 174 248] 270 2025-02-03 16:13:19.023969 +0000 UTC false} {g1mdv2v73mwwf4yay4em0gjtkzdym3d4sy2xp5y4 gpub1pggj7ard9eg82cjtv4u52epjx56nzwgjyg9zpfdjr3a9k7ukakcqt06vfy48uy39qkvrq7ky3368ja9q7hx0xtw6dyc23v 10}}

@zivkovicmilos zivkovicmilos changed the title bug: RPC Batch doesn't support 1 item responses bug: RPC HTTP Batch doesn't support 1 item responses Feb 3, 2025
@n2p5 n2p5 closed this as completed in #3678 Feb 6, 2025
@n2p5 n2p5 closed this as completed in de4a405 Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working help wanted Want to contribute? We recommend these issues.
Projects
Development

Successfully merging a pull request may close this issue.

2 participants