Skip to content

Commit

Permalink
Merge branch 'develop' into feat/wallet-centric-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberphysic4l committed Oct 29, 2023
2 parents cf7508e + c6155f9 commit 4381f38
Show file tree
Hide file tree
Showing 129 changed files with 2,787 additions and 8,637 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/build_tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Build internal tools
on:
pull_request:
paths:
- 'tools/evil-spammer/**'
- 'tools/genesis-snapshot/**'
jobs:

Expand All @@ -23,10 +22,6 @@ jobs:
- name: Print Go version
run: go version

- name: Build evil-spammer tool
working-directory: tools/evil-spammer
run: go mod tidy && go build .

- name: Build genesis-snapshot tool
working-directory: tools/genesis-snapshot
run: go mod tidy && go build .
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,3 @@ dist/
# snapshot and settings file
*.bin
tools/docker-network/docker-network.snapshot
tools/evil-spammer/evil-spammer


2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ run:
tests: true
skip-dirs:
- components/dashboard
- tools/evilwallet
- tools/evil-spammer
skip-files:
- ".*_test.go$"
- "testframework.go"
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ RUN cp ./peering.json /app/peering.json
# using distroless cc "nonroot" image, which includes everything in the base image (glibc, libssl and openssl)
FROM gcr.io/distroless/cc-debian12:nonroot

HEALTHCHECK --interval=10s --timeout=5s --retries=30 CMD ["/app/iota-core", "tools", "node-info"]

# Copy the app dir into distroless image
COPY --chown=nonroot:nonroot --from=build /app /app

Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ RUN mkdir -p /app/data/peerdb
# using distroless cc "nonroot" image, which includes everything in the base image (glibc, libssl and openssl)
FROM gcr.io/distroless/cc-debian12:nonroot

HEALTHCHECK --interval=10s --timeout=5s --retries=30 CMD ["/app/iota-core", "tools", "node-info"]

# Copy the app dir into distroless image
COPY --chown=nonroot:nonroot --from=build /app /app

Expand Down
20 changes: 20 additions & 0 deletions components/app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package app

import (
"fmt"
"os"

"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/app/components/profiling"
"github.com/iotaledger/hive.go/app/components/shutdown"
Expand All @@ -15,6 +18,7 @@ import (
"github.com/iotaledger/iota-core/components/restapi"
coreapi "github.com/iotaledger/iota-core/components/restapi/core"
"github.com/iotaledger/iota-core/components/validator"
"github.com/iotaledger/iota-core/pkg/toolset"
)

var (
Expand All @@ -28,6 +32,12 @@ var (
func App() *app.App {
return app.New(Name, Version,
// app.WithVersionCheck("iotaledger", "iota-core"),
app.WithUsageText(fmt.Sprintf(`Usage of %s (%s %s):
Run '%s tools' to list all available tools.
Command line flags:
`, os.Args[0], Name, Version, os.Args[0])),
app.WithInitComponent(InitComponent),
app.WithComponents(
shutdown.Component,
Expand Down Expand Up @@ -63,5 +73,15 @@ func init() {
AdditionalConfigs: []*app.ConfigurationSet{
app.NewConfigurationSet("peering", "peering", "peeringConfigFilePath", "peeringConfig", false, true, false, "peering.json", "n"),
},
Init: initialize,
}
}

func initialize(_ *app.App) error {
if toolset.ShouldHandleTools() {
toolset.HandleTools()
// HandleTools will call os.Exit
}

return nil
}
9 changes: 7 additions & 2 deletions components/debugapi/node.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package debugapi

import (
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/iota-core/pkg/core/account"
iotago "github.com/iotaledger/iota.go/v4"
Expand All @@ -10,8 +11,12 @@ import (
func validatorsSummary() (*ValidatorsSummaryResponse, error) {
seatManager := deps.Protocol.MainEngineInstance().SybilProtection.SeatManager()
latestSlotIndex := deps.Protocol.MainEngineInstance().Storage.Settings().LatestCommitment().Slot()
latestCommittee := seatManager.Committee(latestSlotIndex)
validatorSeats := []*Validator{}
latestCommittee, exists := seatManager.CommitteeInSlot(latestSlotIndex)
if !exists {
return nil, ierrors.Errorf("committee for slot %d was not selected", latestSlotIndex)
}

var validatorSeats []*Validator
latestCommittee.Accounts().ForEach(func(id iotago.AccountID, pool *account.Pool) bool {
validatorSeats = append(validatorSeats, &Validator{
AccountID: id,
Expand Down
2 changes: 1 addition & 1 deletion components/metricstracker/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ var ParamsMetricsTracker = &ParametersMetricsTracker{}

var params = &app.ComponentParams{
Params: map[string]any{
"metricstracker": ParamsMetricsTracker,
"metricsTracker": ParamsMetricsTracker,
},
}
2 changes: 1 addition & 1 deletion components/p2p/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func provide(c *dig.Container) error {
if err := c.Provide(func(deps p2pDeps) p2pResult {
res := p2pResult{}

privKeyFilePath := filepath.Join(deps.P2PDatabasePath, "identity.key")
privKeyFilePath := filepath.Join(deps.P2PDatabasePath, IdentityPrivateKeyFileName)

// make sure nobody copies around the peer store since it contains the private key of the node
Component.LogInfof(`WARNING: never share your "%s" folder as it contains your node's private key!`, deps.P2PDatabasePath)
Expand Down
3 changes: 2 additions & 1 deletion components/p2p/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (

const (
// CfgPeers defines the static peers this node should retain a connection to (CLI).
CfgPeers = "peers"
CfgPeers = "peers"
IdentityPrivateKeyFileName = "identity.key"
)

// ParametersP2P contains the definition of configuration parameters used by the p2p plugin.
Expand Down
72 changes: 36 additions & 36 deletions components/protocol/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,139 +177,139 @@ func provide(c *dig.Container) error {

func configure() error {
deps.Protocol.Events.Error.Hook(func(err error) {
Component.LogErrorf("Error in Protocol: %s", err)
Component.LogErrorf("ProtocolError, error: %s", err)
})

deps.Protocol.Events.Network.Error.Hook(func(err error, id peer.ID) {
Component.LogErrorf("NetworkError: %s Source: %s", err.Error(), id)
Component.LogErrorf("NetworkError, error: %s, peerID: %s", err.Error(), id)
})

deps.Protocol.Events.Network.BlockReceived.Hook(func(block *model.Block, source peer.ID) {
Component.LogDebugf("BlockReceived: %s", block.ID())
Component.LogDebugf("BlockReceived, blockID: %s, peerID: %s", block.ID(), source)
})

deps.Protocol.Events.Engine.BlockProcessed.Hook(func(blockID iotago.BlockID) {
Component.LogDebugf("BlockProcessed: %s", blockID)
Component.LogDebugf("BlockProcessed, blockID: %s", blockID)
})

deps.Protocol.Events.Engine.AcceptedBlockProcessed.Hook(func(block *blocks.Block) {
Component.LogDebugf("AcceptedBlockProcessed: %s", block.ID())
Component.LogDebugf("AcceptedBlockProcessed, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.Filter.BlockPreFiltered.Hook(func(event *filter.BlockPreFilteredEvent) {
Component.LogDebugf("BlockPreFiltered: %s - %s", event.Block.ID(), event.Reason.Error())
Component.LogDebugf("BlockPreFiltered, blockID: %s, reason: %s", event.Block.ID(), event.Reason.Error())
})

deps.Protocol.Events.Engine.Filter.BlockPreAllowed.Hook(func(blk *model.Block) {
Component.LogDebugf("BlockPreAllowed: %s - %s", blk.ID())
deps.Protocol.Events.Engine.Filter.BlockPreAllowed.Hook(func(block *model.Block) {
Component.LogDebugf("BlockPreAllowed, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.CommitmentFilter.BlockAllowed.Hook(func(block *blocks.Block) {
Component.LogDebugf("CommitmentFilter.BlockAllowed: %s\n", block.ID())
Component.LogDebugf("CommitmentFilter.BlockAllowed, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.CommitmentFilter.BlockFiltered.Hook(func(event *commitmentfilter.BlockFilteredEvent) {
Component.LogWarnf("CommitmentFilter.BlockFiltered: %s - %s\n", event.Block.ID(), event.Reason.Error())
Component.LogWarnf("CommitmentFilter.BlockFiltered, blockID: %s, reason: %s", event.Block.ID(), event.Reason.Error())
})

deps.Protocol.Events.Engine.TipManager.BlockAdded.Hook(func(tip tipmanager.TipMetadata) {
Component.LogDebugf("BlockAdded to tip pool: %s; is strong: %v; is weak: %v", tip.ID(), tip.IsStrongTip(), tip.IsWeakTip())
Component.LogDebugf("TipManager.BlockAdded, blockID: %s, isStrong: %v, isWeak: %v", tip.ID(), tip.IsStrongTip(), tip.IsWeakTip())
})

deps.Protocol.Events.Engine.BlockDAG.BlockSolid.Hook(func(block *blocks.Block) {
Component.LogDebugf("BlockSolid: %s", block.ID())
Component.LogDebugf("BlockDAG.BlockSolid, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.BlockDAG.BlockInvalid.Hook(func(block *blocks.Block, err error) {
Component.LogDebugf("BlockInvalid in blockDAG: %s, error: %v", block.ID(), err.Error())
Component.LogDebugf("BlockDAG.BlockInvalid, blockID: %s, error: %v", block.ID(), err.Error())
})

deps.Protocol.Events.Engine.Booker.BlockBooked.Hook(func(block *blocks.Block) {
Component.LogDebugf("BlockBooked: %s", block.ID())
Component.LogDebugf("BlockBooked, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.Booker.BlockInvalid.Hook(func(block *blocks.Block, err error) {
Component.LogDebugf("BlockInvalid in booker: %s, error: %v", block.ID(), err.Error())
Component.LogDebugf("BlockInvalid in booker, blockID: %s, error: %v", block.ID(), err.Error())
})

deps.Protocol.Events.Engine.BlockGadget.BlockPreAccepted.Hook(func(block *blocks.Block) {
Component.LogDebugf("BlockPreAccepted: %s", block.ID())
Component.LogDebugf("BlockPreAccepted, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.BlockGadget.BlockAccepted.Hook(func(block *blocks.Block) {
Component.LogDebugf("BlockAccepted: %s", block.ID())
Component.LogDebugf("BlockAccepted, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.BlockGadget.BlockPreConfirmed.Hook(func(block *blocks.Block) {
Component.LogDebugf("BlockPreConfirmed: %s", block.ID())
Component.LogDebugf("BlockPreConfirmed, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.BlockGadget.BlockConfirmed.Hook(func(block *blocks.Block) {
Component.LogDebugf("BlockConfirmed: %s", block.ID())
Component.LogDebugf("BlockConfirmed, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.Clock.AcceptedTimeUpdated.Hook(func(time time.Time) {
Component.LogDebugf("AcceptedTimeUpdated: Slot %d @ %s", deps.Protocol.CommittedAPI().TimeProvider().SlotFromTime(time), time)
Component.LogDebugf("AcceptedTimeUpdated, slot: %d @ %s", deps.Protocol.CommittedAPI().TimeProvider().SlotFromTime(time), time)
})

deps.Protocol.Events.Engine.Clock.ConfirmedTimeUpdated.Hook(func(time time.Time) {
Component.LogDebugf("ConfirmedTimeUpdated: Slot %d @ %s", deps.Protocol.CommittedAPI().TimeProvider().SlotFromTime(time), time)
Component.LogDebugf("ConfirmedTimeUpdated, slot: %d @ %s", deps.Protocol.CommittedAPI().TimeProvider().SlotFromTime(time), time)
})

deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(details *notarization.SlotCommittedDetails) {
Component.LogInfof("SlotCommitted: %s - %d", details.Commitment.ID(), details.Commitment.Slot())
Component.LogInfof("SlotCommitted, commitmentID: %s, slot: %d", details.Commitment.ID(), details.Commitment.Slot())
})

deps.Protocol.Events.Engine.SlotGadget.SlotFinalized.Hook(func(index iotago.SlotIndex) {
Component.LogInfof("SlotFinalized: %d", index)
deps.Protocol.Events.Engine.SlotGadget.SlotFinalized.Hook(func(slot iotago.SlotIndex) {
Component.LogInfof("SlotFinalized, slot: %d", slot)
})

deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(block *blocks.Block) {
Component.LogDebugf("BlockScheduled: %s", block.ID())
Component.LogDebugf("BlockScheduled, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.Scheduler.BlockDropped.Hook(func(block *blocks.Block, err error) {
Component.LogDebugf("BlockDropped: %s; reason: %s", block.ID(), err)
Component.LogDebugf("BlockDropped, blockID: %s, reason: %s", block.ID(), err)
})

deps.Protocol.Events.Engine.Scheduler.BlockSkipped.Hook(func(block *blocks.Block) {
Component.LogDebugf("BlockSkipped: %s", block.ID())
Component.LogDebugf("BlockSkipped, blockID: %s", block.ID())
})

deps.Protocol.Events.ChainManager.RequestCommitment.Hook(func(id iotago.CommitmentID) {
Component.LogDebugf("RequestCommitment: %s", id)
Component.LogDebugf("RequestCommitment, commitmentID: %s", id)
})

deps.Protocol.Events.Network.SlotCommitmentRequestReceived.Hook(func(commitmentID iotago.CommitmentID, id peer.ID) {
Component.LogDebugf("SlotCommitmentRequestReceived: %s", commitmentID)
Component.LogDebugf("SlotCommitmentRequestReceived, commitmentID: %s", commitmentID)
})

deps.Protocol.Events.Network.SlotCommitmentReceived.Hook(func(commitment *model.Commitment, id peer.ID) {
Component.LogDebugf("SlotCommitmentReceived: %s", commitment.ID())
Component.LogDebugf("SlotCommitmentReceived, commitmentID: %s", commitment.ID())
})

deps.Protocol.Events.Engine.SybilProtection.CommitteeSelected.Hook(func(committee *account.Accounts, epoch iotago.EpochIndex) {
Component.LogInfof("CommitteeSelected: Epoch %d - %s (reused: %t)", epoch, committee.IDs(), committee.IsReused())
Component.LogInfof("CommitteeSelected, epoch: %d, committeeIDs: %s, reused: %t", epoch, committee.IDs(), committee.IsReused())
})

deps.Protocol.Events.Engine.SybilProtection.RewardsCommitted.Hook(func(epoch iotago.EpochIndex) {
Component.LogInfof("RewardsCommitted: Epoch %d", epoch)
Component.LogInfof("RewardsCommitted, epoch: %d", epoch)
})

deps.Protocol.Events.Engine.Booker.BlockInvalid.Hook(func(block *blocks.Block, err error) {
Component.LogWarnf("Booker BlockInvalid: Block %s - %s", block.ID(), err.Error())
Component.LogWarnf("Booker BlockInvalid, blockID: %s, error: %s", block.ID(), err.Error())
})

deps.Protocol.Events.Engine.SeatManager.OnlineCommitteeSeatAdded.Hook(func(seatIndex account.SeatIndex, account iotago.AccountID) {
Component.LogWarnf("OnlineCommitteeSeatAdded: %s - %d", account.ToHex(), seatIndex)
Component.LogWarnf("OnlineCommitteeSeatAdded, accountID: %s, seatIndex: %d", account.ToHex(), seatIndex)
})

deps.Protocol.Events.Engine.SeatManager.OnlineCommitteeSeatRemoved.Hook(func(seatIndex account.SeatIndex) {
Component.LogWarnf("OnlineCommitteeSeatRemoved: seatIndex: %d", seatIndex)
Component.LogWarnf("OnlineCommitteeSeatRemoved, seatIndex: %d", seatIndex)
})

deps.Protocol.Events.Engine.Booker.TransactionInvalid.Hook(func(transaction mempool.TransactionMetadata, reason error) {
Component.LogWarnf("TransactionInvalid: transaction %s - %s", transaction.ID(), reason.Error())
Component.LogWarnf("TransactionInvalid, transactionID: %s, error: %s", transaction.ID(), reason.Error())
})

return nil
Expand Down
Loading

0 comments on commit 4381f38

Please sign in to comment.