Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: add chainID to BlockValidated rpc #1181

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ type Client struct {
}

type ResultBlockValidated struct {
Result BlockValidationStatus
ChainID string
Result BlockValidationStatus
}

// NewClient returns Client working with given node.
Expand Down Expand Up @@ -807,22 +808,23 @@ func (c *Client) CheckTx(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultChec
return &ctypes.ResultCheckTx{ResponseCheckTx: *res}, nil
}

func (c *Client) BlockValidated(ctx context.Context, height *int64) (*ResultBlockValidated, error) {
func (c *Client) BlockValidated(height *int64) (*ResultBlockValidated, error) {
_, _, chainID := c.node.P2P.Info()
// invalid height
if height == nil || *height < 0 {
return &ResultBlockValidated{Result: -1}, nil
return &ResultBlockValidated{Result: -1, ChainID: chainID}, nil
}
// node has not reached the height yet
if uint64(*height) > c.node.BlockManager.State.Height() {
return &ResultBlockValidated{Result: NotValidated}, nil
return &ResultBlockValidated{Result: NotValidated, ChainID: chainID}, nil
}

if uint64(*height) <= c.node.BlockManager.SettlementValidator.GetLastValidatedHeight() {
return &ResultBlockValidated{Result: SLValidated}, nil
return &ResultBlockValidated{Result: SLValidated, ChainID: chainID}, nil
}

// block is applied, and therefore it is validated at block level but not at state update level
return &ResultBlockValidated{Result: P2PValidated}, nil
return &ResultBlockValidated{Result: P2PValidated, ChainID: chainID}, nil
}

func (c *Client) eventsRoutine(sub tmtypes.Subscription, subscriber string, q tmpubsub.Query, outc chan<- ctypes.ResultEvent) {
Expand Down
4 changes: 1 addition & 3 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,11 @@ func TestValidatedHeight(t *testing.T) {

node.BlockManager.State.SetHeight(test.nodeHeight)

validationResponse, err := rpc.BlockValidated(context.Background(), test.queryHeight)
validationResponse, err := rpc.BlockValidated(test.queryHeight)
require.NoError(err)
require.NotNil(validationResponse)
assert.Equal(test.result, validationResponse.Result)

})

}

err = node.Stop()
Expand Down
2 changes: 1 addition & 1 deletion rpc/json/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,5 @@ func (s *service) BroadcastEvidence(req *http.Request, args *broadcastEvidenceAr

func (s *service) BlockValidated(req *http.Request, args *blockArgs) (*client.ResultBlockValidated, error) {
fmt.Println(args)
return s.client.BlockValidated(req.Context(), (*int64)(&args.Height))
return s.client.BlockValidated((*int64)(&args.Height))
}
Loading