Skip to content

Commit

Permalink
Send commitment via inx
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Nov 20, 2023
1 parent 88b02fb commit 093ebfa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
22 changes: 11 additions & 11 deletions components/inx/server_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ import (
"github.com/iotaledger/hive.go/runtime/event"
"github.com/iotaledger/hive.go/runtime/workerpool"
inx "github.com/iotaledger/inx/go"
"github.com/iotaledger/iota-core/pkg/model"
"github.com/iotaledger/iota-core/pkg/protocol/engine/syncmanager"
iotago "github.com/iotaledger/iota.go/v4"
)

func inxNodeStatus(status *syncmanager.SyncStatus) *inx.NodeStatus {
finalizedCommitmentID := iotago.EmptyCommitmentID
var finalizedCommitment *model.Commitment
// HasPruned is false when a node just started from a snapshot and keeps data of the LastPrunedEpoch, thus still need
// to send finalized commitment.
if !status.HasPruned || status.LatestFinalizedSlot > deps.Protocol.CommittedAPI().TimeProvider().EpochEnd(status.LastPrunedEpoch) {
finalizedCommitment, err := deps.Protocol.MainEngineInstance().Storage.Commitments().Load(status.LatestFinalizedSlot)
var err error
finalizedCommitment, err = deps.Protocol.MainEngineInstance().Storage.Commitments().Load(status.LatestFinalizedSlot)
if err != nil {
return nil
}
finalizedCommitmentID = finalizedCommitment.ID()
}

return &inx.NodeStatus{
IsHealthy: status.NodeSynced,
IsBootstrapped: status.NodeBootstrapped,
LastAcceptedBlockSlot: uint32(status.LastAcceptedBlockSlot),
LastConfirmedBlockSlot: uint32(status.LastConfirmedBlockSlot),
LatestCommitment: inxCommitment(status.LatestCommitment),
LatestFinalizedCommitmentId: inx.NewCommitmentId(finalizedCommitmentID),
PruningEpoch: uint32(status.LastPrunedEpoch),
IsHealthy: status.NodeSynced,
IsBootstrapped: status.NodeBootstrapped,
LastAcceptedBlockSlot: uint32(status.LastAcceptedBlockSlot),
LastConfirmedBlockSlot: uint32(status.LastConfirmedBlockSlot),
LatestCommitment: inxCommitment(status.LatestCommitment),
LatestFinalizedCommitment: inxCommitment(finalizedCommitment),
PruningEpoch: uint32(status.LastPrunedEpoch),
}
}

Expand Down
17 changes: 11 additions & 6 deletions components/inx/server_utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func NewLedgerSpent(s *utxoledger.Spent) (*inx.LedgerSpent, error) {
return l, nil
}

func NewLedgerUpdateBatchBegin(slot iotago.SlotIndex, newOutputsCount int, newSpentsCount int) *inx.LedgerUpdate {
func NewLedgerUpdateBatchBegin(commitmentID iotago.CommitmentID, newOutputsCount int, newSpentsCount int) *inx.LedgerUpdate {
return &inx.LedgerUpdate{
Op: &inx.LedgerUpdate_BatchMarker{
BatchMarker: &inx.LedgerUpdate_Marker{
Slot: uint32(slot),
CommitmentId: inx.NewCommitmentId(commitmentID),
MarkerType: inx.LedgerUpdate_Marker_BEGIN,
CreatedCount: uint32(newOutputsCount),
ConsumedCount: uint32(newSpentsCount),
Expand All @@ -78,11 +78,11 @@ func NewLedgerUpdateBatchBegin(slot iotago.SlotIndex, newOutputsCount int, newSp
}
}

func NewLedgerUpdateBatchEnd(slot iotago.SlotIndex, newOutputsCount int, newSpentsCount int) *inx.LedgerUpdate {
func NewLedgerUpdateBatchEnd(commitmentID iotago.CommitmentID, newOutputsCount int, newSpentsCount int) *inx.LedgerUpdate {
return &inx.LedgerUpdate{
Op: &inx.LedgerUpdate_BatchMarker{
BatchMarker: &inx.LedgerUpdate_Marker{
Slot: uint32(slot),
CommitmentId: inx.NewCommitmentId(commitmentID),
MarkerType: inx.LedgerUpdate_Marker_END,
CreatedCount: uint32(newOutputsCount),
ConsumedCount: uint32(newSpentsCount),
Expand Down Expand Up @@ -191,8 +191,13 @@ func (s *Server) ReadUnspentOutputs(_ *inx.NoParams, srv inx.INX_ReadUnspentOutp

func (s *Server) ListenToLedgerUpdates(req *inx.SlotRangeRequest, srv inx.INX_ListenToLedgerUpdatesServer) error {
createLedgerUpdatePayloadAndSend := func(slot iotago.SlotIndex, outputs utxoledger.Outputs, spents utxoledger.Spents) error {
commitment, err := deps.Protocol.MainEngineInstance().Storage.Commitments().Load(slot)
if err != nil {
return status.Errorf(codes.NotFound, "commitment for slot %d not found", slot)
}

// Send Begin
if err := srv.Send(NewLedgerUpdateBatchBegin(slot, len(outputs), len(spents))); err != nil {
if err := srv.Send(NewLedgerUpdateBatchBegin(commitment.ID(), len(outputs), len(spents))); err != nil {
return fmt.Errorf("send error: %w", err)
}

Expand Down Expand Up @@ -221,7 +226,7 @@ func (s *Server) ListenToLedgerUpdates(req *inx.SlotRangeRequest, srv inx.INX_Li
}

// Send End
if err := srv.Send(NewLedgerUpdateBatchEnd(slot, len(outputs), len(spents))); err != nil {
if err := srv.Send(NewLedgerUpdateBatchEnd(commitment.ID(), len(outputs), len(spents))); err != nil {
return fmt.Errorf("send error: %w", err)
}

Expand Down

0 comments on commit 093ebfa

Please sign in to comment.