Skip to content

Commit

Permalink
Merge pull request #787 from iotaledger/feat/inspection_framework
Browse files Browse the repository at this point in the history
Feat: Make protocol "inspectable"
  • Loading branch information
muXxer authored Mar 1, 2024
2 parents 4e6c142 + 1a802fb commit d2ecc5c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/iotaledger/hive.go/kvstore v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/lo v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/log v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/runtime v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/runtime v0.0.0-20240301015124-eea9bb54a256
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/stringify v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240216141618-d7dfe94bdc1e
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ github.com/iotaledger/hive.go/log v0.0.0-20240223142044-12ffcb37c413 h1:4xKFtHoO
github.com/iotaledger/hive.go/log v0.0.0-20240223142044-12ffcb37c413/go.mod h1:H5tmswUbT3o5+QiM6UPtBv7VnPf+lJtlantgpp2lzUI=
github.com/iotaledger/hive.go/runtime v0.0.0-20240223142044-12ffcb37c413 h1:7O3oSoXlwV5L3/+kt/a1MN3Kwb5oXaaSZaa+aabh7BM=
github.com/iotaledger/hive.go/runtime v0.0.0-20240223142044-12ffcb37c413/go.mod h1:pueoYXud+HmTY2x9j/S6+ZX3M5ZyENFKPDrx3EtcwWs=
github.com/iotaledger/hive.go/runtime v0.0.0-20240301015124-eea9bb54a256 h1:x5h3XFa3Iuy7Fy3JjWUsqZym6WI0X9edRVhEoDQ9JTc=
github.com/iotaledger/hive.go/runtime v0.0.0-20240301015124-eea9bb54a256/go.mod h1:pueoYXud+HmTY2x9j/S6+ZX3M5ZyENFKPDrx3EtcwWs=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240223142044-12ffcb37c413 h1:tQW0K9Ogyfgm3V0wYhRPChOYgrADGlRWF6P4gMY8Zbg=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240223142044-12ffcb37c413/go.mod h1:NK05G4PxwZF1m4jGANJWLhAQ2hP1Nt0L8mgCTFLsSCw=
github.com/iotaledger/hive.go/stringify v0.0.0-20240223142044-12ffcb37c413 h1:QCidFFczZH9NEJTWm0ZzZKMaQ0XUxYyU00dpaH+skqs=
Expand Down
64 changes: 64 additions & 0 deletions pkg/protocol/inspection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package protocol

import (
"github.com/iotaledger/hive.go/runtime/inspection"
"github.com/iotaledger/iota-core/pkg/core/promise"
iotago "github.com/iotaledger/iota.go/v4"
)

// Inspect inspects the protocol and its subcomponents.
func (p *Protocol) Inspect(session ...inspection.Session) inspection.InspectedObject {
return inspection.NewInspectedObject(p, func(protocol inspection.InspectedObject) {
protocol.Add("Commitments", p.Commitments)
protocol.Add("Chains", p.Chains)
}, session...)
}

// Inspect inspects the Commitments and its subcomponents.
func (c *Commitments) Inspect(session ...inspection.Session) inspection.InspectedObject {
return inspection.NewInspectedObject(c, func(commitments inspection.InspectedObject) {
commitments.Add("Root", c.Root.Get())
commitments.Add("Set", c.Set, inspection.SetInspector[*Commitment](c.Set, func(inspectedSet inspection.InspectedObject, element *Commitment) {
inspectedSet.Add(element.LogName(), element)
}))
commitments.Add("cachedRequests", c.cachedRequests, inspection.MapInspector(c.cachedRequests, func(cachedRequests inspection.InspectedObject, commitmentID iotago.CommitmentID, cachedRequest *promise.Promise[*Commitment]) {
cachedRequests.Add(commitmentID.String(), cachedRequest.Result())
}))
}, session...)
}

// Inspect inspects the Commitment and its subcomponents.
func (c *Commitment) Inspect(session ...inspection.Session) inspection.InspectedObject {
return inspection.NewInspectedObject(c, func(commitment inspection.InspectedObject) {
commitment.Add("Parent", c.Parent.Get())
commitment.Add("MainChild", c.MainChild.Get())
commitment.Add("Chain", c.Chain.Get())
commitment.Add("Children", c.Children, inspection.SetInspector[*Commitment](c.Children, func(children inspection.InspectedObject, child *Commitment) {
children.Add(child.LogName(), child)
}))
}, session...)
}

// Inspect inspects the Chains and its subcomponents.
func (c *Chains) Inspect(session ...inspection.Session) inspection.InspectedObject {
return inspection.NewInspectedObject(c, func(chains inspection.InspectedObject) {
chains.Add("Main", c.Main.Get())
chains.Add("HeaviestClaimedCandidate", c.HeaviestClaimedCandidate.Get())
chains.Add("HeaviestAttestedCandidate", c.HeaviestAttestedCandidate.Get())
chains.Add("HeaviestAttestedCandidate", c.HeaviestAttestedCandidate.Get())
chains.Add("Set", c.Set, inspection.SetInspector[*Chain](c.Set, func(set inspection.InspectedObject, chain *Chain) {
set.Add(chain.LogName(), chain)
}))
}, session...)
}

// Inspect inspects the Chain and its subcomponents.
func (c *Chain) Inspect(session ...inspection.Session) inspection.InspectedObject {
return inspection.NewInspectedObject(c, func(chain inspection.InspectedObject) {
chain.Add("ForkingPoint", c.ForkingPoint.Get())
chain.Add("ParentChain", c.ParentChain.Get())
chain.Add("ChildChains", c.ChildChains, inspection.SetInspector[*Chain](c.ChildChains, func(childChains inspection.InspectedObject, chain *Chain) {
childChains.Add(chain.LogName(), chain)
}))
}, session...)
}
2 changes: 1 addition & 1 deletion tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ require (
github.com/iotaledger/hive.go/kvstore v0.0.0-20240223142044-12ffcb37c413 // indirect
github.com/iotaledger/hive.go/lo v0.0.0-20240223142044-12ffcb37c413 // indirect
github.com/iotaledger/hive.go/log v0.0.0-20240223142044-12ffcb37c413 // indirect
github.com/iotaledger/hive.go/runtime v0.0.0-20240223142044-12ffcb37c413 // indirect
github.com/iotaledger/hive.go/runtime v0.0.0-20240301015124-eea9bb54a256 // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240223142044-12ffcb37c413 // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20240223142044-12ffcb37c413 // indirect
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240216141618-d7dfe94bdc1e // indirect
Expand Down
1 change: 1 addition & 0 deletions tools/gendoc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ github.com/iotaledger/hive.go/log v0.0.0-20240223142044-12ffcb37c413 h1:4xKFtHoO
github.com/iotaledger/hive.go/log v0.0.0-20240223142044-12ffcb37c413/go.mod h1:H5tmswUbT3o5+QiM6UPtBv7VnPf+lJtlantgpp2lzUI=
github.com/iotaledger/hive.go/runtime v0.0.0-20240223142044-12ffcb37c413 h1:7O3oSoXlwV5L3/+kt/a1MN3Kwb5oXaaSZaa+aabh7BM=
github.com/iotaledger/hive.go/runtime v0.0.0-20240223142044-12ffcb37c413/go.mod h1:pueoYXud+HmTY2x9j/S6+ZX3M5ZyENFKPDrx3EtcwWs=
github.com/iotaledger/hive.go/runtime v0.0.0-20240301015124-eea9bb54a256/go.mod h1:pueoYXud+HmTY2x9j/S6+ZX3M5ZyENFKPDrx3EtcwWs=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240223142044-12ffcb37c413 h1:tQW0K9Ogyfgm3V0wYhRPChOYgrADGlRWF6P4gMY8Zbg=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240223142044-12ffcb37c413/go.mod h1:NK05G4PxwZF1m4jGANJWLhAQ2hP1Nt0L8mgCTFLsSCw=
github.com/iotaledger/hive.go/stringify v0.0.0-20240223142044-12ffcb37c413 h1:QCidFFczZH9NEJTWm0ZzZKMaQ0XUxYyU00dpaH+skqs=
Expand Down

0 comments on commit d2ecc5c

Please sign in to comment.