Skip to content
Snippets Groups Projects
Unverified Commit 0be22ca3 authored by Luca Moser's avatar Luca Moser Committed by GitHub
Browse files

Merges v0.2.1 changes to master (#612)


* Fix setup wiki article link in readme (#594)

* add snapshot file to releaser archives (#592)

* Double spend check (#606)

* Fix: added a check for doublespends

* Fix: added a check for double spends

* Fix: fixed iport cycle

* Feat: replaced error with error variable

* Feat: store tangle in factory

* Update dapps/faucet/packages/faucet.go

Co-authored-by: default avatarWolfgang Welz <welzwo@gmail.com>

* makes send tx web API handler synced

Co-authored-by: default avatarHans Moog <hm@mkjc.net>
Co-authored-by: default avatarWolfgang Welz <welzwo@gmail.com>
Co-authored-by: default avatarLuca Moser <moser.luca@gmail.com>

* Adds tips broadcaster to gossip plugin (#608)

* adds tips broadcaster to gossip plugin

* adds missing for loop

* addresses review comments

* bumps network and database versions (#610)

* Revert "bumps network and database versions (#610)"

This reverts commit 3e626eac.

* Revert "Revert "bumps network and database versions (#610)""

This reverts commit 9aa3d1bb.

* Adds blacklist and PoW requirement to the faucet (#609)

* adds blacklist and PoW requirement to the faucet

* fixes wrong condition to check pow

* fix faucet payload marhsaling

* don't test payload data if not payload data set

* updates changelog for v0.2.1 (#611)

Co-authored-by: default avatarRajiv Shah <rajivshah1@icloud.com>
Co-authored-by: default avatarWolfgang Welz <welzwo@gmail.com>
Co-authored-by: default avatarHans Moog <3293976+hmoog@users.noreply.github.com>
Co-authored-by: default avatarHans Moog <hm@mkjc.net>
parent f172c96f
No related branches found
No related tags found
No related merge requests found
......@@ -4,8 +4,10 @@ import (
"net/http"
goSync "sync"
"github.com/iotaledger/goshimmer/dapps/faucet"
faucetpayload "github.com/iotaledger/goshimmer/dapps/faucet/packages/payload"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/messagelayer"
"github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/iotaledger/hive.go/logger"
......@@ -20,9 +22,10 @@ const (
var (
// plugin is the plugin instance of the web API info endpoint plugin.
plugin *node.Plugin
once goSync.Once
log *logger.Logger
plugin *node.Plugin
once goSync.Once
log *logger.Logger
fundingMu goSync.Mutex
)
// Plugin gets the plugin instance.
......@@ -41,6 +44,8 @@ func configure(plugin *node.Plugin) {
// requestFunds creates a faucet request (0-value) message with the given destination address and
// broadcasts it to the node's neighbors. It returns the message ID if successful.
func requestFunds(c echo.Context) error {
fundingMu.Lock()
defer fundingMu.Unlock()
var request Request
var addr address.Address
if err := c.Bind(&request); err != nil {
......@@ -55,8 +60,11 @@ func requestFunds(c echo.Context) error {
return c.JSON(http.StatusBadRequest, Response{Error: "Invalid address"})
}
// build faucet message with transaction factory
msg := messagelayer.MessageFactory().IssuePayload(faucetpayload.New(addr))
faucetPayload, err := faucetpayload.New(addr, config.Node().GetInt(faucet.CfgFaucetPoWDifficulty))
if err != nil {
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
}
msg := messagelayer.MessageFactory().IssuePayload(faucetPayload)
if msg == nil {
return c.JSON(http.StatusInternalServerError, Response{Error: "Fail to send faucetrequest"})
}
......
......@@ -2,6 +2,8 @@ package sendtransaction
import (
"net/http"
"sync"
"time"
"github.com/iotaledger/goshimmer/dapps/valuetransfers"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
......@@ -9,8 +11,16 @@ import (
"github.com/labstack/echo"
)
var (
sendTxMu sync.Mutex
maxBookedAwaitTime = 5 * time.Second
)
// Handler sends a transaction.
func Handler(c echo.Context) error {
sendTxMu.Lock()
defer sendTxMu.Unlock()
var request Request
if err := c.Bind(&request); err != nil {
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
......@@ -28,12 +38,18 @@ func Handler(c echo.Context) error {
}
// Prepare value payload and send the message to tangle
payload := valuetransfers.ValueObjectFactory().IssueTransaction(tx)
payload, err := valuetransfers.ValueObjectFactory().IssueTransaction(tx)
if err != nil {
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
}
_, err = issuer.IssuePayload(payload)
if err != nil {
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
}
if err := valuetransfers.AwaitTransactionToBeBooked(tx.ID(), maxBookedAwaitTime); err != nil {
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
}
return c.JSON(http.StatusOK, Response{TransactionID: tx.ID().String()})
}
......
......@@ -66,8 +66,11 @@ func Handler(c echo.Context) error {
tx := transaction.New(inputs, outputs)
// Prepare value payload and send the message to tangle
payload := valuetransfers.ValueObjectFactory().IssueTransaction(tx)
_, err := issuer.IssuePayload(payload)
payload, err := valuetransfers.ValueObjectFactory().IssueTransaction(tx)
if err != nil {
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
}
_, err = issuer.IssuePayload(payload)
if err != nil {
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
}
......
......@@ -85,6 +85,7 @@ func (d *DockerContainer) CreateGoShimmerPeer(config GoShimmerConfig) error {
fmt.Sprintf("--valueLayer.fcob.averageNetworkDelay=%d", ParaFCoBAverageNetworkDelay),
fmt.Sprintf("--node.disablePlugins=%s", config.DisabledPlugins),
fmt.Sprintf("--pow.difficulty=%d", ParaPoWDifficulty),
fmt.Sprintf("--faucet.powDifficulty=%d", ParaPoWFaucetDifficulty),
fmt.Sprintf("--gracefulshutdown.waitToKillTime=%d", ParaWaitToKill),
fmt.Sprintf("--node.enablePlugins=%s", func() string {
var plugins []string
......
......@@ -37,6 +37,8 @@ var (
ParaPoWDifficulty = 2
// ParaWaitToKill defines the time to wait before killing the node.
ParaWaitToKill = 60
// ParaPoWFaucetDifficulty defines the PoW difficulty for faucet payloads.
ParaPoWFaucetDifficulty = 2
)
var (
......
......@@ -9,7 +9,6 @@ import (
"testing"
"time"
faucet_payload "github.com/iotaledger/goshimmer/dapps/faucet/packages/payload"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address/signaturescheme"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance"
......@@ -81,33 +80,28 @@ func SendDataMessage(t *testing.T, peer *framework.Peer, data []byte, number int
func SendFaucetRequestOnRandomPeer(t *testing.T, peers []*framework.Peer, numMessages int) (ids map[string]DataMessageSent, addrBalance map[string]map[balance.Color]int64) {
ids = make(map[string]DataMessageSent, numMessages)
addrBalance = make(map[string]map[balance.Color]int64)
for _, p := range peers {
addr := p.Seed().Address(0).String()
addrBalance[addr] = make(map[balance.Color]int64)
addrBalance[addr][balance.ColorIOTA] = 0
}
for i := 0; i < numMessages; i++ {
peer := peers[rand.Intn(len(peers))]
id, sent := SendFaucetRequest(t, peer)
addr := peer.Seed().Address(uint64(i))
id, sent := SendFaucetRequest(t, peer, addr)
ids[id] = sent
addrBalance[peer.Seed().Address(0).String()][balance.ColorIOTA] += framework.ParaFaucetTokensPerRequest
addrBalance[addr.String()] = map[balance.Color]int64{
balance.ColorIOTA: framework.ParaFaucetTokensPerRequest,
}
}
return ids, addrBalance
}
// SendFaucetRequest sends a data message on a given peer and returns the id and a DataMessageSent struct.
func SendFaucetRequest(t *testing.T, peer *framework.Peer) (string, DataMessageSent) {
addr := peer.Seed().Address(0)
func SendFaucetRequest(t *testing.T, peer *framework.Peer, addr address.Address) (string, DataMessageSent) {
resp, err := peer.SendFaucetRequest(addr.String())
require.NoErrorf(t, err, "Could not send faucet request on %s", peer.String())
sent := DataMessageSent{
id: resp.ID,
// save payload to be able to compare API response
data: faucet_payload.New(addr).Bytes(),
id: resp.ID,
data: nil,
issuerPublicKey: peer.Identity.PublicKey().String(),
}
return resp.ID, sent
......@@ -143,7 +137,9 @@ func CheckForMessageIds(t *testing.T, peers []*framework.Peer, ids map[string]Da
msgSent := ids[msg.ID]
assert.Equalf(t, msgSent.issuerPublicKey, msg.IssuerPublicKey, "messageID=%s, issuer=%s not correct issuer in %s.", msgSent.id, msgSent.issuerPublicKey, peer.String())
assert.Equalf(t, msgSent.data, msg.Payload, "messageID=%s, issuer=%s data not equal in %s.", msgSent.id, msgSent.issuerPublicKey, peer.String())
if msgSent.data != nil {
assert.Equalf(t, msgSent.data, msg.Payload, "messageID=%s, issuer=%s data not equal in %s.", msgSent.id, msgSent.issuerPublicKey, peer.String())
}
assert.Truef(t, msg.Metadata.Solid, "messageID=%s, issuer=%s not solid in %s.", msgSent.id, msgSent.issuerPublicKey, peer.String())
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment