Skip to content
Snippets Groups Projects
Commit 21872576 authored by RUANO RINCON Santiago's avatar RUANO RINCON Santiago
Browse files

mmm, test, not working. unable to cast masterpow payload

parent a26fc752
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ import (
"github.com/iotaledger/goshimmer/packages/tangle/payload"
"github.com/cockroachdb/errors"
"github.com/iotaledger/hive.go/cerrors"
"github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/stringify"
)
......@@ -45,10 +46,15 @@ type Payload struct {
// NewMasterPoWPayload creates a measure payload
func NewMasterPoWPayload(cpuUsage float64) *Payload {
return &Payload{
var _tmp float64 = 64
fmt.Print("cpuUsage: ", cpuUsage)
return Payload{
payloadType: Type,
payloadSubType: payloadSubTypeMeasureRequest,
cpuUsage: cpuUsage,
// payloadSubType: payloadSubTypeMeasureRequest,
payloadSubType: uint8(1),
cpuUsage: _tmp,
}
}
......@@ -71,7 +77,7 @@ func FromBytes(bytes []byte) (result *Payload, consumedBytes int, err error) {
marshalUtil := marshalutil.New(bytes)
//if payload, err := PayloadFromMarshalUtil(marshalutil) ; err != nil {
if result, err := PayloadFromMarshalUtil(marshalUtil) ; err != nil {
if result, err = PayloadFromMarshalUtil(marshalUtil) ; err != nil {
err = errors.Errorf("failed to parse MasterPoWPayload from MarshalUtil: %w", err)
return
}
......@@ -83,7 +89,8 @@ func FromBytes(bytes []byte) (result *Payload, consumedBytes int, err error) {
}
// PayloadFromMarshalUtil is a wrapper for simplified unmarshaling in a byte stream using the marshalUtil package.
func PayloadFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (*Payload, error) {
func PayloadFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *Payload, err error) {
// TODO: mv result -> payload?
//payload, err := marshalUtil.Parse(func(data []byte) (interface{}, int, error) { return FromBytes(data) })
readStartOffset := marshalUtil.ReadOffset()
......@@ -91,12 +98,17 @@ func PayloadFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (*Payload, err
// read data
// TODO: has to be &{}?
result = &Payload{}
_, err := marshalUtil.ReadUint32()
payloadSize, err := marshalUtil.ReadUint32()
if err != nil {
//err = fmt.Errorf("failed to parse payload size of test echo payload: %w", err)
err = errors.Errorf("failed to parse payload size of test echo payload: %w", err)
return
}
// a payloadSize of 0 indicates the payload is omitted and the payload is nil
if payloadSize == 0 {
return
}
result.payloadType, err = payload.TypeFromMarshalUtil(marshalUtil)
if err != nil {
//err = fmt.Errorf("failed to parse payload type of master pow payload: %w", err)
......@@ -104,6 +116,8 @@ func PayloadFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (*Payload, err
return
}
parsedBytes := marshalUtil.ReadOffset() - 8 // skip the payload size and type
// TODO:
result.payloadSubType, err = marshalUtil.ReadUint8()
if err != nil {
......@@ -111,18 +125,27 @@ func PayloadFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (*Payload, err
return
}
result.echoTime, err = marshalUtil.ReadFloat64()
result.cpuUsage, err = marshalUtil.ReadFloat64()
if err != nil {
//err = fmt.Errorf("failed to parse sent time of master pow payload: %w", err)
err = errors.Errorf("failed to parse sent time of master pow payload: %w", err)
return
}
// return the number of bytes we processed
parsedBytes = marshalUtil.ReadOffset() - readStartOffset
if parsedBytes != int(payloadSize)+4 { // skip the payload size
err = errors.Errorf("parsed bytes (%d) did not match expected size (%d): %w", parsedBytes, payloadSize, cerrors.ErrParseBytesFailed)
return
}
if err != nil {
err = fmt.Errorf("failed to parse masterpow payload: %w", err)
return &Payload{}, err
}
return payload.(*Payload), nil
//return result.(*Payload), nil
return
}
......@@ -131,9 +154,15 @@ func (p *Payload) Type() payload.Type {
return p.payloadType
}
// SentTime returns the time that payload was sent.
// EchoTime returns the time that payload was sent.
func (p *Payload) EchoTime() int64 {
return p.echoTime
//TODO to be removed
return 1
}
// CpuUsage returns the cpuUsage measurement.
func (p *Payload) CpuUsage() float64 {
return p.cpuUsage
}
// Bytes marshals the syncbeacon payload into a sequence of bytes.
......@@ -145,7 +174,7 @@ func (p *Payload) Bytes() []byte {
// marshal the p specific information
marshalUtil.WriteUint32(payload.TypeLength + uint32(objectLength))
marshalUtil.WriteBytes(Type.Bytes())
marshalUtil.WriteInt64(p.echoTime)
marshalUtil.WriteFloat64(p.cpuUsage)
// return result
return marshalUtil.Bytes()
......@@ -154,5 +183,5 @@ func (p *Payload) Bytes() []byte {
// String returns a human readable version of syncbeacon payload (for debug purposes).
func (p *Payload) String() string {
return stringify.Struct("syncMasterPoWPayload",
stringify.StructField("echoTime", p.echoTime))
stringify.StructField("cpuUsage", p.cpuUsage))
}
......@@ -15,7 +15,7 @@ import (
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
"github.com/iotaledger/goshimmer/packages/clock"
//"github.com/iotaledger/goshimmer/packages/clock"
gossipPkg "github.com/iotaledger/goshimmer/packages/gossip"
"github.com/iotaledger/goshimmer/packages/shutdown"
"github.com/iotaledger/goshimmer/packages/tangle"
......@@ -145,8 +145,8 @@ func configureEvents() {
}
log.Info("Master pow message received")
log.Info(msgPayload.EchoTime())
//pow.Tune(currentDifficulty["hola"])
log.Info(msgPayload.CpuUsage())
pow.Tune(1)
//log.Info(currentDifficulty["hola"])
cpuUsage = metrics.CPUUsage()
......@@ -163,7 +163,8 @@ func broadcastMasterPoWPayload() (doneSignal chan struct{}) {
go func() {
defer close(doneSignal)
syncMasterPoWPayload := payload.NewMasterPoWPayload(clock.SyncedTime().UnixNano())
//syncMasterPoWPayload := payload.NewMasterPoWPayload(clock.SyncedTime().UnixNano())
syncMasterPoWPayload := payload.NewMasterPoWPayload(metrics.CPUUsage())
msg, err := messagelayer.Tangle().IssuePayload(syncMasterPoWPayload)
if err != nil {
log.Warnf("error issuing master PoW message: %w", err)
......
......@@ -67,7 +67,8 @@ func DoPOW(msg []byte) (uint64, error) {
// get the PoW worker
worker := Worker()
log.Debugw("start PoW", "difficulty", difficulty, "numWorkers", numWorkers)
//log.Debugw("start PoW", "difficulty", difficulty, "numWorkers", numWorkers)
log.Info("start PoW", "difficulty", difficulty, "numWorkers", numWorkers)
ctx, cancel := context.WithTimeout(context.Background(), parentsRefreshInterval)
defer cancel()
......
......@@ -8,6 +8,7 @@ import (
analysisdashboard "github.com/iotaledger/goshimmer/plugins/analysis/dashboard"
analysisserver "github.com/iotaledger/goshimmer/plugins/analysis/server"
"github.com/iotaledger/goshimmer/plugins/chat"
"github.com/iotaledger/goshimmer/plugins/masterpow"
"github.com/iotaledger/goshimmer/plugins/networkdelay"
"github.com/iotaledger/goshimmer/plugins/prometheus"
"github.com/iotaledger/goshimmer/plugins/remotelog"
......@@ -29,4 +30,5 @@ var Research = node.Plugins(
activity.Plugin(),
chat.App(),
testecho.Plugin(),
masterpow.Plugin(),
)
......@@ -14,6 +14,7 @@ import (
"github.com/iotaledger/goshimmer/packages/shutdown"
"github.com/iotaledger/goshimmer/packages/tangle"
"github.com/iotaledger/goshimmer/plugins/messagelayer"
"github.com/iotaledger/goshimmer/plugins/pow"
"github.com/iotaledger/goshimmer/plugins/testecho/payload"
)
......@@ -27,6 +28,8 @@ var (
plugin *node.Plugin
once sync.Once
log *logger.Logger
currentDifficulty int
)
// Plugin gets the plugin instance.
......@@ -40,6 +43,7 @@ func Plugin() *node.Plugin {
// configure events
func configure(_ *node.Plugin) {
log = logger.NewLogger(PluginName)
currentDifficulty = 1
configureEvents()
......@@ -82,6 +86,9 @@ func configureEvents() {
log.Info("Echo request received")
//log.Info(parsedPayload.echoTime)
log.Info(msgPayload.EchoTime())
currentDifficulty = (currentDifficulty + 1) % 22
pow.Tune(currentDifficulty)
log.Info(currentDifficulty)
})
}))
......
......@@ -22,7 +22,7 @@ services:
--prometheus.bindAddress=0.0.0.0:9312
--prometheus.processMetrics=false
--node.enablePlugins=analysis-server,analysis-dashboard,prometheus
--node.disablePlugins=portcheck,clock,dashboard,analysis-client,gossip,drng,issuer,messagelayer,mana,pow,valuetransfers,consensus,webapi,webapibroadcastdataendpoint,webapifindtransactionhashesendpoint,webapigetneighborsendpoint,webapigettransactionobjectsbyhashendpoint,webapigettransactiontrytesbyhashendpoint,testecho
--node.disablePlugins=portcheck,clock,dashboard,analysis-client,gossip,drng,issuer,messagelayer,mana,pow,valuetransfers,consensus,webapi,webapibroadcastdataendpoint,webapifindtransactionhashesendpoint,webapigetneighborsendpoint,webapigettransactionobjectsbyhashendpoint,webapigettransactiontrytesbyhashendpoint,masterpow
volumes:
- ./config.docker.json:/tmp/config.json:ro
- goshimmer-cache:/go
......@@ -97,7 +97,7 @@ services:
command: >
--config=/tmp/config.json
--database.directory=/tmp/mainnetdb
--node.enablePlugins=bootstrap,"webapi tools endpoint",testecho
--node.enablePlugins=bootstrap,"webapi tools endpoint",masterpow
--messageLayer.snapshot.file=/tmp/assets/7R1itJx5hVuo9w9hjg5cwKFmek4HMSoBDgJZN8hKGxih.bin
--messageLayer.snapshot.genesisNode=
--node.disablePlugins=portcheck,clock
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment