From 8bdabeb3a8faf671a04c5580ffc27cd2915cbc2a Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Thu, 16 Nov 2023 16:24:11 +0100 Subject: [PATCH 1/2] Fixed INX failing to send the UTXO for accepted tx --- components/inx/server_utxo.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/inx/server_utxo.go b/components/inx/server_utxo.go index 4868e5859..eb0c4e9eb 100644 --- a/components/inx/server_utxo.go +++ b/components/inx/server_utxo.go @@ -29,7 +29,7 @@ func NewLedgerOutput(o *utxoledger.Output) (*inx.LedgerOutput, error) { } includedSlot := o.SlotBooked() - if includedSlot <= latestCommitment.Slot() { + if includedSlot > 0 && includedSlot <= latestCommitment.Slot() { includedCommitment, err := deps.Protocol.MainEngineInstance().Storage.Commitments().Load(includedSlot) if err != nil { return nil, ierrors.Wrapf(err, "failed to load commitment with slot: %d", includedSlot) @@ -54,7 +54,7 @@ func NewLedgerSpent(s *utxoledger.Spent) (*inx.LedgerSpent, error) { latestCommitment := deps.Protocol.MainEngineInstance().SyncManager.LatestCommitment() spentSlot := s.SlotSpent() - if spentSlot <= latestCommitment.Slot() { + if spentSlot > 0 && spentSlot <= latestCommitment.Slot() { spentCommitment, err := deps.Protocol.MainEngineInstance().Storage.Commitments().Load(spentSlot) if err != nil { return nil, ierrors.Wrapf(err, "failed to load commitment with slot: %d", spentSlot) From a35490f310a9eed2a10c600ea49d6ee04a7fc285 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Thu, 16 Nov 2023 16:39:25 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Don=E2=80=99t=20send=20payloads=20over=20IN?= =?UTF-8?q?X=20if=20the=20context=20got=20cancelled=20before?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/inx/server_blocks.go | 20 ++++++++++++++++++++ components/inx/server_utxo.go | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/components/inx/server_blocks.go b/components/inx/server_blocks.go index 07a0a8ed3..6f95a99ee 100644 --- a/components/inx/server_blocks.go +++ b/components/inx/server_blocks.go @@ -46,6 +46,12 @@ func (s *Server) ListenToBlocks(_ *inx.NoParams, srv inx.INX_ListenToBlocksServe unhook := deps.Protocol.Events.Engine.Booker.BlockBooked.Hook(func(block *blocks.Block) { payload := inx.NewBlockWithBytes(block.ID(), block.ModelBlock().Data()) + + if ctx.Err() != nil { + // context is done, so we don't need to send the payload + return + } + if err := srv.Send(payload); err != nil { Component.LogErrorf("send error: %v", err) cancel() @@ -74,6 +80,13 @@ func (s *Server) ListenToAcceptedBlocks(_ *inx.NoParams, srv inx.INX_ListenToAcc if err != nil { Component.LogErrorf("get block metadata error: %v", err) cancel() + + return + } + + if ctx.Err() != nil { + // context is done, so we don't need to send the payload + return } if err := srv.Send(payload); err != nil { @@ -104,6 +117,13 @@ func (s *Server) ListenToConfirmedBlocks(_ *inx.NoParams, srv inx.INX_ListenToCo if err != nil { Component.LogErrorf("get block metadata error: %v", err) cancel() + + return + } + + if ctx.Err() != nil { + // context is done, so we don't need to send the payload + return } if err := srv.Send(payload); err != nil { diff --git a/components/inx/server_utxo.go b/components/inx/server_utxo.go index eb0c4e9eb..a5fb5dfc4 100644 --- a/components/inx/server_utxo.go +++ b/components/inx/server_utxo.go @@ -367,6 +367,8 @@ func (s *Server) ListenToAcceptedTransactions(_ *inx.NoParams, srv inx.INX_Liste }); err != nil { Component.LogErrorf("error creating payload: %v", err) cancel() + + return } var created []*inx.LedgerOutput @@ -387,6 +389,8 @@ func (s *Server) ListenToAcceptedTransactions(_ *inx.NoParams, srv inx.INX_Liste }); err != nil { Component.LogErrorf("error creating payload: %v", err) cancel() + + return } payload := &inx.AcceptedTransaction{ @@ -395,6 +399,12 @@ func (s *Server) ListenToAcceptedTransactions(_ *inx.NoParams, srv inx.INX_Liste Consumed: consumed, Created: created, } + + if ctx.Err() != nil { + // context is done, so we don't need to send the payload + return + } + if err := srv.Send(payload); err != nil { Component.LogErrorf("send error: %v", err) cancel()