Skip to content

Commit 0d0cf4f

Browse files
authored
Merge pull request #1054 from iotaledger/develop
Merge v0.5.0 to master
2 parents 03d9f6e + 51bac59 commit 0d0cf4f

File tree

293 files changed

+22411
-2562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

293 files changed

+22411
-2562
lines changed

.github/workflows/integration-tests.yml

+34
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,37 @@ jobs:
284284
with:
285285
name: ${{ env.TEST_NAME }}
286286
path: tools/integration-tests/logs
287+
288+
mana:
289+
name: mana
290+
env:
291+
TEST_NAME: mana
292+
runs-on: ubuntu-latest
293+
steps:
294+
295+
- name: Check out code
296+
uses: actions/checkout@v2
297+
298+
- name: Build GoShimmer image
299+
run: docker build -t iotaledger/goshimmer .
300+
301+
- name: Pull additional Docker images
302+
run: |
303+
docker pull angelocapossele/drand:1.1.3
304+
docker pull gaiaadm/pumba:latest
305+
docker pull gaiadocker/iproute2:latest
306+
307+
- name: Run integration tests
308+
run: docker-compose -f tools/integration-tests/tester/docker-compose.yml up --abort-on-container-exit --exit-code-from tester --build
309+
310+
- name: Create logs from tester
311+
if: always()
312+
run: |
313+
docker logs tester &> tools/integration-tests/logs/tester.log
314+
315+
- name: Save logs as artifacts
316+
if: always()
317+
uses: actions/upload-artifact@v1
318+
with:
319+
name: ${{ env.TEST_NAME }}
320+
path: tools/integration-tests/logs

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# v0.5.0 - 2021-03-11
2+
* Add Mana (currently not used by any of the modules)
3+
* Add Mana APIs
4+
* Add Mana section to the local dashboard
5+
* Add Mana section to the Pollen Analyzer dashboard
6+
* Add Mana section to the Grafana dashboard
7+
* Refactor the Consensus Manager to be independent from the concrete consensus mechanism implemented
8+
* Improve Tangle visualizer
9+
* Improve documentation
10+
* **Breaking**: bumps network and database versions
11+
112
# v0.4.1 - 2021-03-02
213
* Add orphanage analysis tool
314
* Add documentation web-api

client/mana.go

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
package client
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
7+
webapi_mana "github.com/iotaledger/goshimmer/plugins/webapi/mana"
8+
)
9+
10+
const (
11+
routeGetMana = "mana"
12+
routeGetAllMana = "mana/all"
13+
routeGetManaPercentile = "mana/percentile"
14+
routeGetOnlineAccessMana = "mana/access/online"
15+
routeGetOnlineConsensusMana = "mana/consensus/online"
16+
routeGetNHighestAccessMana = "mana/access/nhighest"
17+
routeGetNHighestConsensusMana = "mana/consensus/nhighest"
18+
routePending = "mana/pending"
19+
routePastConsensusVector = "mana/consensus/past"
20+
routePastConsensusEventLogs = "mana/consensus/logs"
21+
)
22+
23+
// GetOwnMana returns the access and consensus mana of the node this api client is communicating with.
24+
func (api *GoShimmerAPI) GetOwnMana() (*webapi_mana.GetManaResponse, error) {
25+
res := &webapi_mana.GetManaResponse{}
26+
if err := api.do(http.MethodGet, routeGetMana,
27+
&webapi_mana.GetManaRequest{NodeID: ""}, res); err != nil {
28+
return nil, err
29+
}
30+
return res, nil
31+
}
32+
33+
// GetManaFullNodeID returns the access and consensus mana of the node specified in the argument.
34+
// Note, that for the node to understand which nodeID we are referring to, short node ID is not sufficient.
35+
func (api *GoShimmerAPI) GetManaFullNodeID(fullNodeID string) (*webapi_mana.GetManaResponse, error) {
36+
res := &webapi_mana.GetManaResponse{}
37+
if err := api.do(http.MethodGet, routeGetMana,
38+
&webapi_mana.GetManaRequest{NodeID: fullNodeID}, res); err != nil {
39+
return nil, err
40+
}
41+
return res, nil
42+
}
43+
44+
// GetMana returns the access and consensus mana a node has based on its shortNodeID.
45+
func (api *GoShimmerAPI) GetMana(shortNodeID string) (*webapi_mana.GetManaResponse, error) {
46+
// ask the node about the full mana map and filter out based on shortID
47+
allManaRes := &webapi_mana.GetAllManaResponse{}
48+
if err := api.do(http.MethodGet, routeGetAllMana,
49+
nil, allManaRes); err != nil {
50+
return nil, err
51+
}
52+
res := &webapi_mana.GetManaResponse{ShortNodeID: shortNodeID}
53+
// look for node's mana values in the map
54+
for _, nodeStr := range allManaRes.Access {
55+
if nodeStr.ShortNodeID == shortNodeID {
56+
res.Access = nodeStr.Mana
57+
break
58+
}
59+
}
60+
for _, nodeStr := range allManaRes.Consensus {
61+
if nodeStr.ShortNodeID == shortNodeID {
62+
res.Consensus = nodeStr.Mana
63+
break
64+
}
65+
}
66+
return res, nil
67+
}
68+
69+
// GetAllMana returns the mana perception of the node in the network.
70+
func (api *GoShimmerAPI) GetAllMana() (*webapi_mana.GetAllManaResponse, error) {
71+
res := &webapi_mana.GetAllManaResponse{}
72+
if err := api.do(http.MethodGet, routeGetAllMana,
73+
nil, res); err != nil {
74+
return nil, err
75+
}
76+
return res, nil
77+
}
78+
79+
// GetManaPercentile returns the mana percentile for access and consensus mana of a node.
80+
func (api *GoShimmerAPI) GetManaPercentile(fullNodeID string) (*webapi_mana.GetPercentileResponse, error) {
81+
res := &webapi_mana.GetPercentileResponse{}
82+
if err := api.do(http.MethodGet, routeGetManaPercentile,
83+
&webapi_mana.GetPercentileRequest{NodeID: fullNodeID}, res); err != nil {
84+
return nil, err
85+
}
86+
return res, nil
87+
}
88+
89+
// GetOnlineAccessMana returns the sorted list of online access mana of nodes.
90+
func (api *GoShimmerAPI) GetOnlineAccessMana() (*webapi_mana.GetOnlineResponse, error) {
91+
res := &webapi_mana.GetOnlineResponse{}
92+
if err := api.do(http.MethodGet, routeGetOnlineAccessMana,
93+
nil, res); err != nil {
94+
return nil, err
95+
}
96+
return res, nil
97+
}
98+
99+
// GetOnlineConsensusMana returns the sorted list of online consensus mana of nodes.
100+
func (api *GoShimmerAPI) GetOnlineConsensusMana() (*webapi_mana.GetOnlineResponse, error) {
101+
res := &webapi_mana.GetOnlineResponse{}
102+
if err := api.do(http.MethodGet, routeGetOnlineConsensusMana,
103+
nil, res); err != nil {
104+
return nil, err
105+
}
106+
return res, nil
107+
}
108+
109+
// GetNHighestAccessMana returns the N highest access mana holders in the network, sorted in descending order.
110+
func (api *GoShimmerAPI) GetNHighestAccessMana(n int) (*webapi_mana.GetNHighestResponse, error) {
111+
res := &webapi_mana.GetNHighestResponse{}
112+
if err := api.do(http.MethodGet, func() string {
113+
return fmt.Sprintf("%s?number=%d", routeGetNHighestAccessMana, n)
114+
}(), nil, res); err != nil {
115+
return nil, err
116+
}
117+
return res, nil
118+
}
119+
120+
// GetNHighestConsensusMana returns the N highest consensus mana holders in the network, sorted in descending order.
121+
func (api *GoShimmerAPI) GetNHighestConsensusMana(n int) (*webapi_mana.GetNHighestResponse, error) {
122+
res := &webapi_mana.GetNHighestResponse{}
123+
if err := api.do(http.MethodGet, func() string {
124+
return fmt.Sprintf("%s?number=%d", routeGetNHighestConsensusMana, n)
125+
}(), nil, res); err != nil {
126+
return nil, err
127+
}
128+
return res, nil
129+
}
130+
131+
// GetPending returns the mana (bm2) that will be pledged by spending the output specified.
132+
func (api *GoShimmerAPI) GetPending(outputID string) (*webapi_mana.PendingResponse, error) {
133+
res := &webapi_mana.PendingResponse{}
134+
if err := api.do(http.MethodGet, routePending,
135+
&webapi_mana.PendingRequest{OutputID: outputID}, res); err != nil {
136+
return nil, err
137+
}
138+
return res, nil
139+
}
140+
141+
// GetPastConsensusManaVector returns the consensus base mana vector of a time in the past.
142+
func (api *GoShimmerAPI) GetPastConsensusManaVector(t int64) (*webapi_mana.PastConsensusManaVectorResponse, error) {
143+
res := &webapi_mana.PastConsensusManaVectorResponse{}
144+
if err := api.do(http.MethodGet, routePastConsensusVector,
145+
&webapi_mana.PastConsensusManaVectorRequest{Timestamp: t}, res); err != nil {
146+
return nil, err
147+
}
148+
return res, nil
149+
}
150+
151+
// GetPastConsensusVectorMetadata returns the consensus base mana vector metadata of a time in the past.
152+
func (api *GoShimmerAPI) GetPastConsensusVectorMetadata() (*webapi_mana.PastConsensusVectorMetadataResponse, error) {
153+
res := &webapi_mana.PastConsensusVectorMetadataResponse{}
154+
if err := api.do(http.MethodGet, routePastConsensusVector, nil, res); err != nil {
155+
return nil, err
156+
}
157+
return res, nil
158+
}
159+
160+
// GetConsensusEventLogs returns the consensus event logs or the nodeIDs specified.
161+
func (api *GoShimmerAPI) GetConsensusEventLogs(nodeIDs []string) (*webapi_mana.GetEventLogsResponse, error) {
162+
res := &webapi_mana.GetEventLogsResponse{}
163+
if err := api.do(http.MethodGet, routePastConsensusEventLogs,
164+
&webapi_mana.GetEventLogsRequest{NodeIDs: nodeIDs}, res); err != nil {
165+
return nil, err
166+
}
167+
return res, nil
168+
}

client/value.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
)
99

1010
const (
11-
routeAttachments = "value/attachments"
12-
routeGetTxnByID = "value/transactionByID"
13-
routeSendTxn = "value/sendTransaction"
14-
routeSendTxnByJSON = "value/sendTransactionByJson"
15-
routeUnspentOutputs = "value/unspentOutputs"
11+
routeAttachments = "value/attachments"
12+
routeGetTxnByID = "value/transactionByID"
13+
routeSendTxn = "value/sendTransaction"
14+
routeSendTxnByJSON = "value/sendTransactionByJson"
15+
routeUnspentOutputs = "value/unspentOutputs"
16+
routeAllowedPledgeNodeIDs = "value/allowedManaPledge"
1617
)
1718

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

7980
return res.TransactionID, nil
8081
}
82+
83+
// GetAllowedManaPledgeNodeIDs returns the list of allowed mana pledge IDs.
84+
func (api *GoShimmerAPI) GetAllowedManaPledgeNodeIDs() (*webapi_value.AllowedManaPledgeResponse, error) {
85+
res := &webapi_value.AllowedManaPledgeResponse{}
86+
if err := api.do(http.MethodGet, routeAllowedPledgeNodeIDs, nil, res); err != nil {
87+
return nil, err
88+
}
89+
90+
return res, nil
91+
}

client/wallet/connector.go

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package wallet
33
import (
44
"github.com/iotaledger/goshimmer/client/wallet/packages/address"
55
"github.com/iotaledger/goshimmer/packages/ledgerstate"
6+
"github.com/iotaledger/goshimmer/packages/mana"
67
)
78

89
// Connector represents an interface that defines how the wallet interacts with the network. A wallet can either be used
@@ -11,4 +12,5 @@ type Connector interface {
1112
UnspentOutputs(addresses ...address.Address) (unspentOutputs map[address.Address]map[ledgerstate.OutputID]*Output, err error)
1213
SendTransaction(transaction *ledgerstate.Transaction) (err error)
1314
RequestFaucetFunds(address address.Address) (err error)
15+
GetAllowedPledgeIDs() (pledgeIDMap map[mana.Type][]string, err error)
1416
}

client/wallet/output.go

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package wallet
22

33
import (
4+
"time"
5+
46
"github.com/iotaledger/goshimmer/client/wallet/packages/address"
57
"github.com/iotaledger/goshimmer/packages/ledgerstate"
68
"github.com/iotaledger/hive.go/stringify"
@@ -14,6 +16,7 @@ type Output struct {
1416
OutputID ledgerstate.OutputID
1517
Balances *ledgerstate.ColoredBalances
1618
InclusionState InclusionState
19+
Metadata OutputMetadata
1720
}
1821

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

45+
// OutputMetadata is metadata about the output.
46+
type OutputMetadata struct {
47+
// Timestamp is the timestamp of the tx that created the output.
48+
Timestamp time.Time
49+
}
50+
4251
// String returns a human-readable representation of the InclusionState.
4352
func (i InclusionState) String() string {
4453
return stringify.Struct("InclusionState",

client/wallet/packages/address/address.go

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package address
33
import (
44
"github.com/iotaledger/goshimmer/packages/ledgerstate"
55
"github.com/iotaledger/hive.go/stringify"
6+
"github.com/mr-tron/base58"
67
)
78

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

26+
// Base58 returns the base58 encoded address.
27+
func (a Address) Base58() string {
28+
return base58.Encode(a.AddressBytes[:])
29+
}
30+
2531
func (a Address) String() string {
2632
return stringify.Struct("Address",
2733
stringify.StructField("Address", a.Address()),

client/wallet/sendfunds_options.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,28 @@ func Remainder(addr address.Address) SendFundsOption {
6262
}
6363
}
6464

65+
// AccessManaPledgeID is an option for SendFunds call that defines the nodeID to pledge access mana to.
66+
func AccessManaPledgeID(nodeID string) SendFundsOption {
67+
return func(options *sendFundsOptions) error {
68+
options.AccessManaPledgeID = nodeID
69+
return nil
70+
}
71+
}
72+
73+
// ConsensusManaPledgeID is an option for SendFunds call that defines the nodeID to pledge consensus mana to.
74+
func ConsensusManaPledgeID(nodeID string) SendFundsOption {
75+
return func(options *sendFundsOptions) error {
76+
options.ConsensusManaPledgeID = nodeID
77+
return nil
78+
}
79+
}
80+
6581
// sendFundsOptions is a struct that is used to aggregate the optional parameters provided in the SendFunds call.
6682
type sendFundsOptions struct {
67-
Destinations map[address.Address]map[ledgerstate.Color]uint64
68-
RemainderAddress address.Address
83+
Destinations map[address.Address]map[ledgerstate.Color]uint64
84+
RemainderAddress address.Address
85+
AccessManaPledgeID string
86+
ConsensusManaPledgeID string
6987
}
7088

7189
// buildSendFundsOptions is a utility function that constructs the sendFundsOptions.

client/wallet/serverstatus.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package wallet
22

33
// ServerStatus defines the information of connected server
44
type ServerStatus struct {
5-
ID string
6-
Synced bool
7-
Version string
5+
ID string
6+
Synced bool
7+
Version string
8+
ManaDecay float64
89
}

0 commit comments

Comments
 (0)