Skip to content

Commit

Permalink
Merge pull request #1054 from iotaledger/develop
Browse files Browse the repository at this point in the history
Merge v0.5.0 to master
  • Loading branch information
capossele authored Mar 11, 2021
2 parents 03d9f6e + 51bac59 commit 0d0cf4f
Show file tree
Hide file tree
Showing 293 changed files with 22,411 additions and 2,562 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,37 @@ jobs:
with:
name: ${{ env.TEST_NAME }}
path: tools/integration-tests/logs

mana:
name: mana
env:
TEST_NAME: mana
runs-on: ubuntu-latest
steps:

- name: Check out code
uses: actions/checkout@v2

- name: Build GoShimmer image
run: docker build -t iotaledger/goshimmer .

- name: Pull additional Docker images
run: |
docker pull angelocapossele/drand:1.1.3
docker pull gaiaadm/pumba:latest
docker pull gaiadocker/iproute2:latest
- name: Run integration tests
run: docker-compose -f tools/integration-tests/tester/docker-compose.yml up --abort-on-container-exit --exit-code-from tester --build

- name: Create logs from tester
if: always()
run: |
docker logs tester &> tools/integration-tests/logs/tester.log
- name: Save logs as artifacts
if: always()
uses: actions/upload-artifact@v1
with:
name: ${{ env.TEST_NAME }}
path: tools/integration-tests/logs
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# v0.5.0 - 2021-03-11
* Add Mana (currently not used by any of the modules)
* Add Mana APIs
* Add Mana section to the local dashboard
* Add Mana section to the Pollen Analyzer dashboard
* Add Mana section to the Grafana dashboard
* Refactor the Consensus Manager to be independent from the concrete consensus mechanism implemented
* Improve Tangle visualizer
* Improve documentation
* **Breaking**: bumps network and database versions

# v0.4.1 - 2021-03-02
* Add orphanage analysis tool
* Add documentation web-api
Expand Down
168 changes: 168 additions & 0 deletions client/mana.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package client

import (
"fmt"
"net/http"

webapi_mana "github.com/iotaledger/goshimmer/plugins/webapi/mana"
)

const (
routeGetMana = "mana"
routeGetAllMana = "mana/all"
routeGetManaPercentile = "mana/percentile"
routeGetOnlineAccessMana = "mana/access/online"
routeGetOnlineConsensusMana = "mana/consensus/online"
routeGetNHighestAccessMana = "mana/access/nhighest"
routeGetNHighestConsensusMana = "mana/consensus/nhighest"
routePending = "mana/pending"
routePastConsensusVector = "mana/consensus/past"
routePastConsensusEventLogs = "mana/consensus/logs"
)

// GetOwnMana returns the access and consensus mana of the node this api client is communicating with.
func (api *GoShimmerAPI) GetOwnMana() (*webapi_mana.GetManaResponse, error) {
res := &webapi_mana.GetManaResponse{}
if err := api.do(http.MethodGet, routeGetMana,
&webapi_mana.GetManaRequest{NodeID: ""}, res); err != nil {
return nil, err
}
return res, nil
}

// GetManaFullNodeID returns the access and consensus mana of the node specified in the argument.
// Note, that for the node to understand which nodeID we are referring to, short node ID is not sufficient.
func (api *GoShimmerAPI) GetManaFullNodeID(fullNodeID string) (*webapi_mana.GetManaResponse, error) {
res := &webapi_mana.GetManaResponse{}
if err := api.do(http.MethodGet, routeGetMana,
&webapi_mana.GetManaRequest{NodeID: fullNodeID}, res); err != nil {
return nil, err
}
return res, nil
}

// GetMana returns the access and consensus mana a node has based on its shortNodeID.
func (api *GoShimmerAPI) GetMana(shortNodeID string) (*webapi_mana.GetManaResponse, error) {
// ask the node about the full mana map and filter out based on shortID
allManaRes := &webapi_mana.GetAllManaResponse{}
if err := api.do(http.MethodGet, routeGetAllMana,
nil, allManaRes); err != nil {
return nil, err
}
res := &webapi_mana.GetManaResponse{ShortNodeID: shortNodeID}
// look for node's mana values in the map
for _, nodeStr := range allManaRes.Access {
if nodeStr.ShortNodeID == shortNodeID {
res.Access = nodeStr.Mana
break
}
}
for _, nodeStr := range allManaRes.Consensus {
if nodeStr.ShortNodeID == shortNodeID {
res.Consensus = nodeStr.Mana
break
}
}
return res, nil
}

// GetAllMana returns the mana perception of the node in the network.
func (api *GoShimmerAPI) GetAllMana() (*webapi_mana.GetAllManaResponse, error) {
res := &webapi_mana.GetAllManaResponse{}
if err := api.do(http.MethodGet, routeGetAllMana,
nil, res); err != nil {
return nil, err
}
return res, nil
}

// GetManaPercentile returns the mana percentile for access and consensus mana of a node.
func (api *GoShimmerAPI) GetManaPercentile(fullNodeID string) (*webapi_mana.GetPercentileResponse, error) {
res := &webapi_mana.GetPercentileResponse{}
if err := api.do(http.MethodGet, routeGetManaPercentile,
&webapi_mana.GetPercentileRequest{NodeID: fullNodeID}, res); err != nil {
return nil, err
}
return res, nil
}

// GetOnlineAccessMana returns the sorted list of online access mana of nodes.
func (api *GoShimmerAPI) GetOnlineAccessMana() (*webapi_mana.GetOnlineResponse, error) {
res := &webapi_mana.GetOnlineResponse{}
if err := api.do(http.MethodGet, routeGetOnlineAccessMana,
nil, res); err != nil {
return nil, err
}
return res, nil
}

// GetOnlineConsensusMana returns the sorted list of online consensus mana of nodes.
func (api *GoShimmerAPI) GetOnlineConsensusMana() (*webapi_mana.GetOnlineResponse, error) {
res := &webapi_mana.GetOnlineResponse{}
if err := api.do(http.MethodGet, routeGetOnlineConsensusMana,
nil, res); err != nil {
return nil, err
}
return res, nil
}

// GetNHighestAccessMana returns the N highest access mana holders in the network, sorted in descending order.
func (api *GoShimmerAPI) GetNHighestAccessMana(n int) (*webapi_mana.GetNHighestResponse, error) {
res := &webapi_mana.GetNHighestResponse{}
if err := api.do(http.MethodGet, func() string {
return fmt.Sprintf("%s?number=%d", routeGetNHighestAccessMana, n)
}(), nil, res); err != nil {
return nil, err
}
return res, nil
}

// GetNHighestConsensusMana returns the N highest consensus mana holders in the network, sorted in descending order.
func (api *GoShimmerAPI) GetNHighestConsensusMana(n int) (*webapi_mana.GetNHighestResponse, error) {
res := &webapi_mana.GetNHighestResponse{}
if err := api.do(http.MethodGet, func() string {
return fmt.Sprintf("%s?number=%d", routeGetNHighestConsensusMana, n)
}(), nil, res); err != nil {
return nil, err
}
return res, nil
}

// GetPending returns the mana (bm2) that will be pledged by spending the output specified.
func (api *GoShimmerAPI) GetPending(outputID string) (*webapi_mana.PendingResponse, error) {
res := &webapi_mana.PendingResponse{}
if err := api.do(http.MethodGet, routePending,
&webapi_mana.PendingRequest{OutputID: outputID}, res); err != nil {
return nil, err
}
return res, nil
}

// GetPastConsensusManaVector returns the consensus base mana vector of a time in the past.
func (api *GoShimmerAPI) GetPastConsensusManaVector(t int64) (*webapi_mana.PastConsensusManaVectorResponse, error) {
res := &webapi_mana.PastConsensusManaVectorResponse{}
if err := api.do(http.MethodGet, routePastConsensusVector,
&webapi_mana.PastConsensusManaVectorRequest{Timestamp: t}, res); err != nil {
return nil, err
}
return res, nil
}

// GetPastConsensusVectorMetadata returns the consensus base mana vector metadata of a time in the past.
func (api *GoShimmerAPI) GetPastConsensusVectorMetadata() (*webapi_mana.PastConsensusVectorMetadataResponse, error) {
res := &webapi_mana.PastConsensusVectorMetadataResponse{}
if err := api.do(http.MethodGet, routePastConsensusVector, nil, res); err != nil {
return nil, err
}
return res, nil
}

// GetConsensusEventLogs returns the consensus event logs or the nodeIDs specified.
func (api *GoShimmerAPI) GetConsensusEventLogs(nodeIDs []string) (*webapi_mana.GetEventLogsResponse, error) {
res := &webapi_mana.GetEventLogsResponse{}
if err := api.do(http.MethodGet, routePastConsensusEventLogs,
&webapi_mana.GetEventLogsRequest{NodeIDs: nodeIDs}, res); err != nil {
return nil, err
}
return res, nil
}
21 changes: 16 additions & 5 deletions client/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
)

const (
routeAttachments = "value/attachments"
routeGetTxnByID = "value/transactionByID"
routeSendTxn = "value/sendTransaction"
routeSendTxnByJSON = "value/sendTransactionByJson"
routeUnspentOutputs = "value/unspentOutputs"
routeAttachments = "value/attachments"
routeGetTxnByID = "value/transactionByID"
routeSendTxn = "value/sendTransaction"
routeSendTxnByJSON = "value/sendTransactionByJson"
routeUnspentOutputs = "value/unspentOutputs"
routeAllowedPledgeNodeIDs = "value/allowedManaPledge"
)

// GetAttachments gets the attachments of a transaction ID
Expand Down Expand Up @@ -78,3 +79,13 @@ func (api *GoShimmerAPI) SendTransactionByJSON(txn webapi_value.SendTransactionB

return res.TransactionID, nil
}

// GetAllowedManaPledgeNodeIDs returns the list of allowed mana pledge IDs.
func (api *GoShimmerAPI) GetAllowedManaPledgeNodeIDs() (*webapi_value.AllowedManaPledgeResponse, error) {
res := &webapi_value.AllowedManaPledgeResponse{}
if err := api.do(http.MethodGet, routeAllowedPledgeNodeIDs, nil, res); err != nil {
return nil, err
}

return res, nil
}
2 changes: 2 additions & 0 deletions client/wallet/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wallet
import (
"github.com/iotaledger/goshimmer/client/wallet/packages/address"
"github.com/iotaledger/goshimmer/packages/ledgerstate"
"github.com/iotaledger/goshimmer/packages/mana"
)

// Connector represents an interface that defines how the wallet interacts with the network. A wallet can either be used
Expand All @@ -11,4 +12,5 @@ type Connector interface {
UnspentOutputs(addresses ...address.Address) (unspentOutputs map[address.Address]map[ledgerstate.OutputID]*Output, err error)
SendTransaction(transaction *ledgerstate.Transaction) (err error)
RequestFaucetFunds(address address.Address) (err error)
GetAllowedPledgeIDs() (pledgeIDMap map[mana.Type][]string, err error)
}
9 changes: 9 additions & 0 deletions client/wallet/output.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package wallet

import (
"time"

"github.com/iotaledger/goshimmer/client/wallet/packages/address"
"github.com/iotaledger/goshimmer/packages/ledgerstate"
"github.com/iotaledger/hive.go/stringify"
Expand All @@ -14,6 +16,7 @@ type Output struct {
OutputID ledgerstate.OutputID
Balances *ledgerstate.ColoredBalances
InclusionState InclusionState
Metadata OutputMetadata
}

// String returns a human-readable representation of the Output.
Expand All @@ -39,6 +42,12 @@ type InclusionState struct {
Spent bool
}

// OutputMetadata is metadata about the output.
type OutputMetadata struct {
// Timestamp is the timestamp of the tx that created the output.
Timestamp time.Time
}

// String returns a human-readable representation of the InclusionState.
func (i InclusionState) String() string {
return stringify.Struct("InclusionState",
Expand Down
6 changes: 6 additions & 0 deletions client/wallet/packages/address/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package address
import (
"github.com/iotaledger/goshimmer/packages/ledgerstate"
"github.com/iotaledger/hive.go/stringify"
"github.com/mr-tron/base58"
)

// Address represents an address in a wallet. It extends the normal address type with an index number that was used to
Expand All @@ -22,6 +23,11 @@ func (a Address) Address() (ledgerStateAddress ledgerstate.Address) {
return
}

// Base58 returns the base58 encoded address.
func (a Address) Base58() string {
return base58.Encode(a.AddressBytes[:])
}

func (a Address) String() string {
return stringify.Struct("Address",
stringify.StructField("Address", a.Address()),
Expand Down
22 changes: 20 additions & 2 deletions client/wallet/sendfunds_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,28 @@ func Remainder(addr address.Address) SendFundsOption {
}
}

// AccessManaPledgeID is an option for SendFunds call that defines the nodeID to pledge access mana to.
func AccessManaPledgeID(nodeID string) SendFundsOption {
return func(options *sendFundsOptions) error {
options.AccessManaPledgeID = nodeID
return nil
}
}

// ConsensusManaPledgeID is an option for SendFunds call that defines the nodeID to pledge consensus mana to.
func ConsensusManaPledgeID(nodeID string) SendFundsOption {
return func(options *sendFundsOptions) error {
options.ConsensusManaPledgeID = nodeID
return nil
}
}

// sendFundsOptions is a struct that is used to aggregate the optional parameters provided in the SendFunds call.
type sendFundsOptions struct {
Destinations map[address.Address]map[ledgerstate.Color]uint64
RemainderAddress address.Address
Destinations map[address.Address]map[ledgerstate.Color]uint64
RemainderAddress address.Address
AccessManaPledgeID string
ConsensusManaPledgeID string
}

// buildSendFundsOptions is a utility function that constructs the sendFundsOptions.
Expand Down
7 changes: 4 additions & 3 deletions client/wallet/serverstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package wallet

// ServerStatus defines the information of connected server
type ServerStatus struct {
ID string
Synced bool
Version string
ID string
Synced bool
Version string
ManaDecay float64
}
Loading

0 comments on commit 0d0cf4f

Please sign in to comment.