Skip to content

Commit

Permalink
Merge pull request #529 from iotaledger/feat/fix-inx-genesis-slot
Browse files Browse the repository at this point in the history
Fixed INX failing to send the UTXO for accepted tx
  • Loading branch information
alexsporn authored Nov 16, 2023
2 parents d7c7664 + a35490f commit c40917b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
20 changes: 20 additions & 0 deletions components/inx/server_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 12 additions & 2 deletions components/inx/server_utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -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()
Expand Down

0 comments on commit c40917b

Please sign in to comment.