Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:iotaledger/iota-core into feat/r…
Browse files Browse the repository at this point in the history
…eactive-chainmanager
  • Loading branch information
hmoog committed Sep 12, 2023
2 parents 101a1bf + ca451e2 commit fa7a9e5
Show file tree
Hide file tree
Showing 28 changed files with 679 additions and 447 deletions.
58 changes: 50 additions & 8 deletions components/protocol/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package protocol

import (
"context"
"os"
"time"

"github.com/labstack/gommon/bytes"
Expand Down Expand Up @@ -58,11 +59,45 @@ type dependencies struct {
Protocol *protocol.Protocol
}

type jsonProtocolParameters struct {
ProtocolParameters []iotago.ProtocolParameters `serix:"0,mapKey=protocolParameters"`
}

func readProtocolParameters() []iotago.ProtocolParameters {
fileBytes, err := os.ReadFile(ParamsProtocol.ProtocolParametersPath)
if err != nil {
Component.LogInfof("No protocol parameters file (%s) found, skipping import: %s", ParamsProtocol.ProtocolParametersPath, err)
return nil
}

parsedParams := &jsonProtocolParameters{}
if err := iotago.CommonSerixAPI().JSONDecode(context.Background(), fileBytes, parsedParams); err != nil {
Component.LogWarnf("Error parsing protocol parameters file (%s): %s", ParamsProtocol.ProtocolParametersPath, err)
return nil
}

return parsedParams.ProtocolParameters
}

func resetProtocolParameters() {
bytesToWrite, err := iotago.CommonSerixAPI().JSONEncode(context.Background(), jsonProtocolParameters{})
if err != nil {
Component.LogInfof("Error writing protocol parameters file (%s): %s", ParamsProtocol.ProtocolParametersPath, err)
return
}

if err := os.WriteFile(ParamsProtocol.ProtocolParametersPath, bytesToWrite, 0600); err != nil {
Component.LogInfof("Error writing protocol parameters file (%s): %s", ParamsProtocol.ProtocolParametersPath, err)
return
}
}

func initConfigParams(c *dig.Container) error {
type cfgResult struct {
dig.Out
DatabaseEngine hivedb.Engine `name:"databaseEngine"`
BaseToken *BaseToken
DatabaseEngine hivedb.Engine `name:"databaseEngine"`
BaseToken *BaseToken
ProtocolParameters []iotago.ProtocolParameters
}

if err := c.Provide(func() cfgResult {
Expand All @@ -72,8 +107,9 @@ func initConfigParams(c *dig.Container) error {
}

return cfgResult{
DatabaseEngine: dbEngine,
BaseToken: &ParamsProtocol.BaseToken,
DatabaseEngine: dbEngine,
BaseToken: &ParamsProtocol.BaseToken,
ProtocolParameters: readProtocolParameters(),
}
}); err != nil {
Component.LogPanic(err)
Expand All @@ -86,8 +122,9 @@ func provide(c *dig.Container) error {
type protocolDeps struct {
dig.In

DatabaseEngine hivedb.Engine `name:"databaseEngine"`
P2PManager *p2p.Manager
DatabaseEngine hivedb.Engine `name:"databaseEngine"`
ProtocolParameters []iotago.ProtocolParameters
P2PManager *p2p.Manager
}

return c.Provide(func(deps protocolDeps) *protocol.Protocol {
Expand Down Expand Up @@ -132,8 +169,9 @@ func provide(c *dig.Container) error {
blockfilter.WithMaxAllowedWallClockDrift(ParamsProtocol.Filter.MaxAllowedClockDrift),
),
),
// TODO: here we should pass the protocol parameters from the config.
protocol.WithUpgradeOrchestratorProvider(signalingupgradeorchestrator.NewProvider()),
protocol.WithUpgradeOrchestratorProvider(
signalingupgradeorchestrator.NewProvider(signalingupgradeorchestrator.WithProtocolParameters(deps.ProtocolParameters...)),
),
)
})
}
Expand Down Expand Up @@ -277,6 +315,10 @@ func run() error {
Component.LogErrorfAndExit("Error running the Protocol: %s", err.Error())
}
}

//nolint:contextcheck // context might be canceled
resetProtocolParameters()

Component.LogInfo("Gracefully shutting down the Protocol...")
}, daemon.PriorityProtocol)
}
2 changes: 2 additions & 0 deletions components/protocol/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type ParametersProtocol struct {
MaxAllowedClockDrift time.Duration `default:"5s" usage:"the maximum drift our wall clock can have to future blocks being received from the network"`
}

ProtocolParametersPath string `default:"testnet/protocol_parameters.json" usage:"the path of the protocol parameters file"`

BaseToken BaseToken
}

Expand Down
1 change: 1 addition & 0 deletions config_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"filter": {
"maxAllowedClockDrift": "5s"
},
"protocolParametersPath": "testnet/protocol_parameters.json",
"baseToken": {
"name": "Shimmer",
"tickerSymbol": "SMR",
Expand Down
12 changes: 7 additions & 5 deletions documentation/docs/references/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,12 @@ Example:

## <a id="protocol"></a> 9. Protocol

| Name | Description | Type | Default value |
| -------------------------------- | --------------------------- | ------ | ------------- |
| [snapshot](#protocol_snapshot) | Configuration for snapshot | object | |
| [filter](#protocol_filter) | Configuration for filter | object | |
| [baseToken](#protocol_basetoken) | Configuration for baseToken | object | |
| Name | Description | Type | Default value |
| -------------------------------- | ---------------------------------------- | ------ | ---------------------------------- |
| [snapshot](#protocol_snapshot) | Configuration for snapshot | object | |
| [filter](#protocol_filter) | Configuration for filter | object | |
| protocolParametersPath | The path of the protocol parameters file | string | "testnet/protocol_parameters.json" |
| [baseToken](#protocol_basetoken) | Configuration for baseToken | object | |

### <a id="protocol_snapshot"></a> Snapshot

Expand Down Expand Up @@ -366,6 +367,7 @@ Example:
"filter": {
"maxAllowedClockDrift": "5s"
},
"protocolParametersPath": "testnet/protocol_parameters.json",
"baseToken": {
"name": "Shimmer",
"tickerSymbol": "SMR",
Expand Down
35 changes: 18 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ require (
github.com/google/uuid v1.3.1
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/iotaledger/hive.go/ads v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/app v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/constraints v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/crypto v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/ds v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/ierrors v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/kvstore v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/lo v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/logger v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/runtime v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/stringify v0.0.0-20230912002851-de46b7eb1272
github.com/iotaledger/hive.go/ads v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/app v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/constraints v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/crypto v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/ds v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/ierrors v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/kvstore v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/lo v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/logger v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/runtime v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230912172434-dc477e1f5140
github.com/iotaledger/hive.go/stringify v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230829161228-3f4eb50a4d14
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230829160617-69b96c7c9f9b
github.com/iotaledger/iota.go/v4 v4.0.0-20230829160021-46cad51e89d1
github.com/iotaledger/iota.go/v4 v4.0.0-20230912141328-810f7e83d265
github.com/labstack/echo/v4 v4.11.1
github.com/labstack/gommon v0.4.0
github.com/libp2p/go-libp2p v0.30.0
github.com/libp2p/go-libp2p-kad-dht v0.25.0
github.com/libp2p/go-libp2p-kad-dht v0.25.1
github.com/multiformats/go-multiaddr v0.11.0
github.com/multiformats/go-varint v0.0.7
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e
Expand Down Expand Up @@ -58,7 +58,7 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/eclipse/paho.mqtt.golang v1.4.3 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/ethereum/go-ethereum v1.12.2 // indirect
github.com/ethereum/go-ethereum v1.13.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/fjl/memsize v0.0.2 // indirect
Expand All @@ -83,7 +83,7 @@ require (
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/huin/goupnp v1.2.0 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 // indirect
github.com/ipfs/boxo v0.10.0 // indirect
Expand All @@ -106,6 +106,7 @@ require (
github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect
github.com/libp2p/go-libp2p-kbucket v0.6.3 // indirect
github.com/libp2p/go-libp2p-record v0.2.0 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.7.2 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/libp2p/go-nat v0.2.0 // indirect
github.com/libp2p/go-netroute v0.2.1 // indirect
Expand Down
Loading

0 comments on commit fa7a9e5

Please sign in to comment.