Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonastheis committed Mar 22, 2023
1 parent cd840a3 commit 926a762
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/app/blockissuer/blockissuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func New(protocol *protocol.Protocol, localIdentity *identity.LocalIdentity, opt
localIdentity,
protocol.SlotTimeProvider,
func(blockID models.BlockID) (block *blockdag.Block, exists bool) {
return i.protocol.Engine().Tangle.BlockDAG.Block(blockID)
return i.protocol.Engine().Tangle.BlockDAG().Block(blockID)
},
func(countParents int) (parents models.BlockIDs) {
return i.protocol.TipManager.Tips(countParents)
Expand Down
2 changes: 1 addition & 1 deletion packages/app/retainer/retainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (r *Retainer) createStorableBlockMetadata(index slot.Index) (metas []*Block
storage.ForEach(func(blockID models.BlockID, cm *cachedMetadata) bool {
blockMetadata := newBlockMetadata(cm)
if cm.Booker != nil {
blockMetadata.M.ConflictIDs = r.protocol.Engine().Tangle.booker.BlockConflicts(cm.Booker.Block)
blockMetadata.M.ConflictIDs = r.protocol.Engine().Tangle.Booker().BlockConflicts(cm.Booker.Block)
} else {
blockMetadata.M.ConflictIDs = utxo.NewTransactionIDs()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/blockdag"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/booker/markerbooker/markervirtualvoting"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/booker"
"github.com/iotaledger/goshimmer/packages/protocol/models"
"github.com/iotaledger/goshimmer/packages/protocol/models/payload"
"github.com/iotaledger/hive.go/core/slot"
Expand Down Expand Up @@ -293,7 +293,7 @@ func newTestBlock(opts ...options.Option[models.Block]) *Block {
parents.AddStrong(models.EmptyBlockID)
opts = append(opts, models.WithParents(parents))

blk := NewBlock(markervirtualvoting.NewBlock(blockdag.NewBlock(models.NewBlock(opts...))))
blk := NewBlock(booker.NewBlock(blockdag.NewBlock(models.NewBlock(opts...))))
if err := blk.DetermineID(slotTimeProvider); err != nil {
panic(errors.Wrap(err, "could not determine BlockID"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/iotaledger/goshimmer/packages/protocol/engine/consensus/blockgadget"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/blockdag"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/booker/markerbooker/markervirtualvoting"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/booker"
"github.com/iotaledger/goshimmer/packages/protocol/markers"
"github.com/iotaledger/goshimmer/packages/protocol/models"
"github.com/iotaledger/hive.go/crypto/identity"
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestScheduler_AddBlock(t *testing.T) {
tf := NewTestFramework(t, workers.CreateGroup("SchedulerTestFramework"))
tf.Scheduler.Start()

blk := markervirtualvoting.NewBlock(blockdag.NewBlock(models.NewBlock(models.WithStrongParents(tf.Tangle.BlockDAG.BlockIDs("Genesis"))), blockdag.WithSolid(true), blockdag.WithOrphaned(true)), markervirtualvoting.WithBooked(true), markervirtualvoting.WithStructureDetails(markers.NewStructureDetails()))
blk := booker.NewBlock(blockdag.NewBlock(models.NewBlock(models.WithStrongParents(tf.Tangle.BlockDAG.BlockIDs("Genesis"))), blockdag.WithSolid(true), blockdag.WithOrphaned(true)), booker.WithBooked(true), booker.WithStructureDetails(markers.NewStructureDetails()))
require.NoError(t, blk.DetermineID(tf.SlotTimeProvider()))

tf.Scheduler.AddBlock(blk)
Expand Down Expand Up @@ -461,7 +461,7 @@ func TestScheduler_Issue(t *testing.T) {
for i := 0; i < numBlocks; i++ {
block := tf.Tangle.BlockDAG.CreateBlock(fmt.Sprintf("blk-%d", i), models.WithIssuer(tf.Issuer("peer").PublicKey()), models.WithStrongParents(models.NewBlockIDs(tf.Tangle.BlockDAG.Block("Genesis").ID())))
ids.Add(block.ID())
_, _, err := tf.Tangle.Instance.BlockDAG.Attach(block)
_, _, err := tf.Tangle.Instance.BlockDAG().Attach(block)
require.NoError(t, err)
}

Expand Down
4 changes: 4 additions & 0 deletions packages/protocol/engine/tangle/booker/booker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/iotaledger/goshimmer/packages/core/votes/conflicttracker"
"github.com/iotaledger/goshimmer/packages/core/votes/sequencetracker"
"github.com/iotaledger/goshimmer/packages/protocol/engine/ledger/utxo"
"github.com/iotaledger/goshimmer/packages/protocol/engine/sybilprotection"
"github.com/iotaledger/goshimmer/packages/protocol/markers"
"github.com/iotaledger/goshimmer/packages/protocol/models"
"github.com/iotaledger/hive.go/core/slot"
Expand Down Expand Up @@ -62,6 +63,9 @@ type VirtualVoting interface {
// ConflictVotersTotalWeight retrieves the total weight of the Validators voting for a given conflict.
ConflictVotersTotalWeight(conflictID utxo.TransactionID) (totalWeight int64)

// ConflictVoters retrieves Validators voting for a given conflict.
ConflictVoters(conflictID utxo.TransactionID) (voters *sybilprotection.WeightedSet)

// SlotVotersTotalWeight retrieves the total weight of the Validators voting for a given slot.
SlotVotersTotalWeight(slotIndex slot.Index) (totalWeight int64)
}
3 changes: 1 addition & 2 deletions packages/protocol/engine/tsc/testframework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/blockdag"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/booker"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/booker/markerbooker/markervirtualvoting"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tsc"
"github.com/iotaledger/hive.go/runtime/options"
)
Expand All @@ -24,7 +23,7 @@ type TestFramework struct {
Tangle *tangle.TestFramework
BlockDAG *blockdag.TestFramework
Booker *booker.TestFramework
VirtualVoting *markervirtualvoting.TestFramework
VirtualVoting *booker.VirtualVotingTestFramework
}

func NewTestFramework(test *testing.T, tangleTF *tangle.TestFramework, optsTSCManager ...options.Option[tsc.Manager]) *TestFramework {
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/enginemanager/testframework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/iotaledger/goshimmer/packages/protocol/engine/ledger/utxoledger"
"github.com/iotaledger/goshimmer/packages/protocol/engine/notarization/slotnotarization"
"github.com/iotaledger/goshimmer/packages/protocol/engine/sybilprotection/dpos"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/inmemorytangle"
"github.com/iotaledger/goshimmer/packages/protocol/engine/throughputquota/mana1"
"github.com/iotaledger/goshimmer/packages/protocol/enginemanager"
"github.com/iotaledger/goshimmer/packages/storage/utils"
Expand Down Expand Up @@ -61,6 +62,7 @@ func NewEngineManagerTestFramework(t *testing.T, workers *workerpool.Group, iden
dpos.NewProvider(),
mana1.NewProvider(),
slotnotarization.NewProvider(),
inmemorytangle.NewProvider(),
tangleconsensus.NewProvider(),
)

Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/tipmanager/testframework.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewTestFramework(test *testing.T, workers *workerpool.Group, opts ...option
t.Tangle = tangle.NewTestFramework(
test,
t.Engine.Tangle,
markerbooker.NewTestFramework(test, workers.CreateGroup("BookerTestFramework"), t.Engine.Tangle.Booker().(*markerbooker.Booker)),
booker.NewTestFramework(test, workers.CreateGroup("BookerTestFramework"), t.Engine.Tangle.Booker().(*markerbooker.Booker), t.Engine.Tangle.BlockDAG(), t.Engine.Ledger.MemPool(), t.Engine.SybilProtection.Validators(), t.Engine.SlotTimeProvider),
)

t.Instance = New(workers.CreateGroup("TipManager"), t.mockSchedulerBlock, t.optsTipManagerOptions...)
Expand Down
8 changes: 4 additions & 4 deletions plugins/dagsvisualizer/visualizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func registerTangleEvents(plugin *node.Plugin) {
}, event.WithWorkerPool(plugin.WorkerPool))

deps.Protocol.Events.Engine.Tangle.Booker.BlockBooked.Hook(func(evt *booker.BlockBookedEvent) {
conflictIDs := deps.Protocol.Engine().Tangle.booker.BlockConflicts(evt.Block)
conflictIDs := deps.Protocol.Engine().Tangle.Booker().BlockConflicts(evt.Block)

wsBlk := &wsBlock{
Type: BlkTypeTangleBooked,
Expand Down Expand Up @@ -88,7 +88,7 @@ func registerTangleEvents(plugin *node.Plugin) {
}, event.WithWorkerPool(plugin.WorkerPool))

deps.Protocol.Events.Engine.Ledger.MemPool.TransactionAccepted.Hook(func(event *mempool.TransactionEvent) {
attachmentBlock := deps.Protocol.Engine().Tangle.booker.GetEarliestAttachment(event.Metadata.ID())
attachmentBlock := deps.Protocol.Engine().Tangle.Booker().GetEarliestAttachment(event.Metadata.ID())

wsBlk := &wsBlock{
Type: BlkTypeTangleTxConfirmationState,
Expand Down Expand Up @@ -155,7 +155,7 @@ func registerConflictEvents(plugin *node.Plugin) {
Type: BlkTypeConflictWeightChanged,
Data: &conflictWeightChanged{
ID: e.ConflictID.Base58(),
Weight: deps.Protocol.Engine().Tangle.booker.VirtualVoting.ConflictVotersTotalWeight(e.ConflictID),
Weight: deps.Protocol.Engine().Tangle.Booker().VirtualVoting().ConflictVotersTotalWeight(e.ConflictID),
ConfirmationState: conflictConfirmationState.String(),
},
}
Expand Down Expand Up @@ -370,7 +370,7 @@ func newConflictVertex(conflictID utxo.TransactionID) (ret *conflictVertex) {
Conflicts: jsonmodels.NewGetConflictConflictsResponse(conflict.ID(), conflicts),
IsConfirmed: confirmationState.IsAccepted(),
ConfirmationState: confirmationState.String(),
AW: deps.Protocol.Engine().Tangle.booker.VirtualVoting.ConflictVotersTotalWeight(conflictID),
AW: deps.Protocol.Engine().Tangle.Booker().VirtualVoting().ConflictVotersTotalWeight(conflictID),
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/dashboard/conflicts_livefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func sendAllConflicts() {
}

func issuerOfOldestAttachment(conflictID utxo.TransactionID) (id identity.ID) {
block := deps.Protocol.Engine().Tangle.booker.GetEarliestAttachment(conflictID)
block := deps.Protocol.Engine().Tangle.Booker().GetEarliestAttachment(conflictID)
if block != nil {
return block.IssuerID()
}
Expand Down
1 change: 1 addition & 0 deletions plugins/faucet/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/iotaledger/goshimmer/packages/protocol"
"github.com/iotaledger/goshimmer/packages/protocol/engine/ledger/vm/devnetvm"
"github.com/iotaledger/goshimmer/packages/protocol/engine/ledger/vm/devnetvm/indexer"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/booker"
"github.com/iotaledger/hive.go/app/daemon"
"github.com/iotaledger/hive.go/crypto/identity"
"github.com/iotaledger/hive.go/runtime/event"
Expand Down
2 changes: 1 addition & 1 deletion plugins/metrics/metrics_conflicts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var ConflictMetrics = collector.NewCollection(conflictNamespace,
collector.WithHelp("Time since transaction issuance to the conflict acceptance"),
collector.WithInitFunc(func() {
deps.Protocol.Events.Engine.Ledger.MemPool.ConflictDAG.ConflictAccepted.Hook(func(conflict *conflictdag.Conflict[utxo.TransactionID, utxo.OutputID]) {
firstAttachment := deps.Protocol.Engine().Tangle.booker.GetEarliestAttachment(conflict.ID())
firstAttachment := deps.Protocol.Engine().Tangle.Booker().GetEarliestAttachment(conflict.ID())
timeSinceIssuance := time.Since(firstAttachment.IssuingTime()).Milliseconds()
timeIssuanceSeconds := float64(timeSinceIssuance) / 1000
deps.Collector.Update(conflictNamespace, resolutionTime, collector.SingleValue(timeIssuanceSeconds))
Expand Down
2 changes: 1 addition & 1 deletion plugins/remotemetrics/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func onTransactionAccepted(transactionEvent *mempool.TransactionEvent) {
return
}

earliestAttachment := deps.Protocol.Engine().Tangle.booker.GetEarliestAttachment(transactionEvent.Metadata.ID())
earliestAttachment := deps.Protocol.Engine().Tangle.Booker().GetEarliestAttachment(transactionEvent.Metadata.ID())

onBlockFinalized(earliestAttachment.ModelsBlock)
}
Expand Down
7 changes: 4 additions & 3 deletions plugins/webapi/ledgerstate/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/iotaledger/goshimmer/packages/protocol/engine/ledger/utxo"
"github.com/iotaledger/goshimmer/packages/protocol/engine/ledger/vm/devnetvm"
"github.com/iotaledger/goshimmer/packages/protocol/engine/ledger/vm/devnetvm/indexer"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/booker"
"github.com/iotaledger/goshimmer/packages/protocol/models"
"github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/iotaledger/hive.go/app/daemon"
Expand Down Expand Up @@ -269,7 +270,7 @@ func GetConflict(c echo.Context) (err error) {
return c.JSON(http.StatusNotFound, jsonmodels.NewErrorResponse(errors.Errorf("failed to load Conflict with %s", conflictID)))
}

return c.JSON(http.StatusOK, jsonmodels.NewConflictWeight(conflict, conflict.ConfirmationState(), deps.Protocol.Engine().Tangle.booker.VirtualVoting.ConflictVotersTotalWeight(conflictID)))
return c.JSON(http.StatusOK, jsonmodels.NewConflictWeight(conflict, conflict.ConfirmationState(), deps.Protocol.Engine().Tangle.Booker().VirtualVoting().ConflictVotersTotalWeight(conflictID)))
}

// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -328,7 +329,7 @@ func GetConflictVoters(c echo.Context) (err error) {
return c.JSON(http.StatusBadRequest, jsonmodels.NewErrorResponse(err))
}

voters := deps.Protocol.Engine().Tangle.booker.VirtualVoting.ConflictVoters(conflictID)
voters := deps.Protocol.Engine().Tangle.Booker().VirtualVoting().ConflictVoters(conflictID)
defer voters.Detach()

return c.JSON(http.StatusOK, jsonmodels.NewGetConflictVotersResponse(conflictID, voters))
Expand Down Expand Up @@ -470,7 +471,7 @@ func GetTransactionAttachments(c echo.Context) (err error) {
}

blockIDs := models.NewBlockIDs()
_ = deps.Protocol.Engine().Tangle.booker.GetAllAttachments(transactionID).ForEach(func(attachment *booker.Block) error {
_ = deps.Protocol.Engine().Tangle.Booker().GetAllAttachments(transactionID).ForEach(func(attachment *booker.Block) error {
blockIDs.Add(attachment.ID())
return nil
})
Expand Down
6 changes: 3 additions & 3 deletions plugins/webapi/weightprovider/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func configure(_ *node.Plugin) {
func getIssuersHandler(c echo.Context) (err error) {
activeValidatorsString := make([]string, 0)

_ = deps.Protocol.Engine().Tangle.booker.VirtualVoting.Validators.ForEach(func(id identity.ID) error {
_ = deps.Protocol.Engine().SybilProtection.Validators().ForEach(func(id identity.ID) error {
activeValidatorsString = append(activeValidatorsString, id.String())
return nil
})
Expand All @@ -48,14 +48,14 @@ func getIssuersHandler(c echo.Context) (err error) {

func getWeightsHandler(c echo.Context) (err error) {
weightsString := make(map[string]int64)
_ = deps.Protocol.Engine().Tangle.booker.VirtualVoting.Validators.ForEach(func(id identity.ID) error {
_ = deps.Protocol.Engine().SybilProtection.Validators().ForEach(func(id identity.ID) error {
weightsString[id.String()] = lo.Return1(deps.Protocol.Engine().SybilProtection.Weights().Get(id)).Value
return nil
})

resp := Weights{
Weights: weightsString,
TotalWeight: deps.Protocol.Engine().Tangle.booker.VirtualVoting.Validators.TotalWeight(),
TotalWeight: deps.Protocol.Engine().SybilProtection.Validators().TotalWeight(),
}

return c.JSON(http.StatusOK, resp)
Expand Down
2 changes: 2 additions & 0 deletions tools/genesis-snapshot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/iotaledger/goshimmer/packages/protocol/engine/notarization"
"github.com/iotaledger/goshimmer/packages/protocol/engine/notarization/slotnotarization"
"github.com/iotaledger/goshimmer/packages/protocol/engine/sybilprotection/dpos"
"github.com/iotaledger/goshimmer/packages/protocol/engine/tangle/inmemorytangle"
"github.com/iotaledger/goshimmer/packages/protocol/engine/throughputquota/mana1"
"github.com/iotaledger/goshimmer/packages/protocol/models"
"github.com/iotaledger/goshimmer/packages/storage"
Expand Down Expand Up @@ -97,6 +98,7 @@ func diagnosticPrintSnapshotFromFile(filePath string, ledgerProvider module.Prov
dpos.NewProvider(),
mana1.NewProvider(),
slotnotarization.NewProvider(),
inmemorytangle.NewProvider(),
tangleconsensus.NewProvider(),
)
defer e.Shutdown()
Expand Down

0 comments on commit 926a762

Please sign in to comment.