Skip to content

Commit

Permalink
Merge pull request #870 from iotaledger/fix/inx-blockMetadata
Browse files Browse the repository at this point in the history
Return accepted/confirmed in ListenToAcceptedBlocks and ListenToConfirmedBlocks
  • Loading branch information
muXxer authored Mar 25, 2024
2 parents 4499ef0 + d71065b commit acb7eeb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions components/inx/server_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/iotaledger/iota-core/pkg/model"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)

func (s *Server) ReadActiveRootBlocks(_ context.Context, _ *inx.NoParams) (*inx.RootBlocksResponse, error) {
Expand Down Expand Up @@ -78,7 +79,10 @@ func (s *Server) ListenToAcceptedBlocks(_ *inx.NoParams, srv inx.INX_ListenToAcc
wp := workerpool.New("ListenToAcceptedBlocks", workerpool.WithWorkerCount(workerCount)).Start()

unhook := deps.Protocol.Events.Engine.BlockGadget.BlockAccepted.Hook(func(block *blocks.Block) {
payload, err := getINXBlockMetadata(block.ID())
payload, err := inx.WrapBlockMetadata(&api.BlockMetadataResponse{
BlockID: block.ID(),
BlockState: api.BlockStateAccepted,
})
if err != nil {
Component.LogErrorf("get block metadata error: %v", err)
cancel()
Expand Down Expand Up @@ -115,7 +119,10 @@ func (s *Server) ListenToConfirmedBlocks(_ *inx.NoParams, srv inx.INX_ListenToCo
wp := workerpool.New("ListenToConfirmedBlocks", workerpool.WithWorkerCount(workerCount)).Start()

unhook := deps.Protocol.Events.Engine.BlockGadget.BlockConfirmed.Hook(func(block *blocks.Block) {
payload, err := getINXBlockMetadata(block.ID())
payload, err := inx.WrapBlockMetadata(&api.BlockMetadataResponse{
BlockID: block.ID(),
BlockState: api.BlockStateConfirmed,
})
if err != nil {
Component.LogErrorf("get block metadata error: %v", err)
cancel()
Expand Down
4 changes: 4 additions & 0 deletions tools/docker-network/tests/eventapiframework.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func (e *EventAPIDockerTestFramework) AssertBlockMetadataStateAcceptedBlocks(ctx
for {
select {
case blk := <-acceptedChan:
require.Equal(e.Testing, api.BlockStateAccepted, blk.BlockState, "Block %s is pending in BlockMetadataAccepted topic", blk.BlockID.ToHex())

resp, err := eventClt.Client.BlockMetadataByBlockID(ctx, blk.BlockID)
require.NoError(e.Testing, err)
// accepted, confirmed are accepted
Expand All @@ -110,6 +112,8 @@ func (e *EventAPIDockerTestFramework) AssertBlockMetadataStateConfirmedBlocks(ct
for {
select {
case blk := <-acceptedChan:
require.Equal(e.Testing, api.BlockStateConfirmed, blk.BlockState, "Block %s is pending in BlockMetadataConfirmed topic", blk.BlockID.ToHex())

resp, err := eventClt.Client.BlockMetadataByBlockID(ctx, blk.BlockID)
require.NoError(e.Testing, err)
require.NotEqualf(e.Testing, api.BlockStatePending, resp.BlockState, "Block %s is pending in BlockMetadataConfirmed endpoint", blk.BlockID.ToHex())
Expand Down

0 comments on commit acb7eeb

Please sign in to comment.