NebulousLabs / Sia-Ant-Farm

A tool for setting up small testnets for Sia.
MIT License
24 stars 16 forks source link

Run locally without internet connection #77

Open roughpandaz opened 6 years ago

roughpandaz commented 6 years ago

@avahowell This package require Ants to connect through the public internet.

Is there a way to run this locally without any internet connections? Currently, I get the error no UPnP-enabled gateway found, which seems to be a result of this configuration.

If not, is there any options for running a local testnet just to play with the sia API?

Thanks in advance.

roughpandaz commented 6 years ago

I've got it running locally but get the error message:

[INFO] starting ant 0 with config {localhost:52168 :52169 :52170 antfarm-data/ant397733575  siad [gateway miner] 0}
2018/05/25 11:58:10 error clearing upnp ports for ant: goupnp: SOAP request got HTTP 500 Internal Server Error: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns="urn:schemas-upnp-org:control-1-0"><errorCode>714</errorCode><errorDescription>NoSuchEntryInArray</errorDescription></UPnPError></detail></s:Fault></s:Body></s:Envelope>

However, it seems to be mining and creating blocks. Full output below.

[INFO] starting ant 0 with config {localhost:52168 :52169 :52170 antfarm-data/ant397733575  siad [gateway miner] 0}
2018/05/25 11:58:10 error clearing upnp ports for ant: goupnp: SOAP request got HTTP 500 Internal Server Error: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns="urn:schemas-upnp-org:control-1-0"><errorCode>714</errorCode><errorDescription>NoSuchEntryInArray</errorDescription></UPnPError></detail></s:Fault></s:Body></s:Envelope>
[INFO] starting ant 1 with config {localhost:52181 :52182 :52183 ./antfarm-data/host1 host1 siad [host] 100000}
2018/05/25 11:58:15 error clearing upnp ports for ant: goupnp: SOAP request got HTTP 500 Internal Server Error: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns="urn:schemas-upnp-org:control-1-0"><errorCode>714</errorCode><errorDescription>NoSuchEntryInArray</errorDescription></UPnPError></detail></s:Fault></s:Body></s:Envelope>
[INFO] starting ant 2 with config {localhost:52205 :52206 :52207 ./antfarm-data/host2 host2 siad [host] 100000}
2018/05/25 11:58:29 error clearing upnp ports for ant: goupnp: SOAP request got HTTP 500 Internal Server Error: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns="urn:schemas-upnp-org:control-1-0"><errorCode>714</errorCode><errorDescription>NoSuchEntryInArray</errorDescription></UPnPError></detail></s:Fault></s:Body></s:Envelope>
[INFO] starting ant 3 with config {localhost:52236 :52237 :52238 ./antfarm-data/host3 host3 siad [host] 100000}
2018/05/25 11:58:31 [./antfarm-data/host1 jobHost INFO]: succesfully performed host announcement
2018/05/25 11:58:34 error clearing upnp ports for ant: goupnp: SOAP request got HTTP 500 Internal Server Error: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns="urn:schemas-upnp-org:control-1-0"><errorCode>714</errorCode><errorDescription>NoSuchEntryInArray</errorDescription></UPnPError></detail></s:Fault></s:Body></s:Envelope>
[INFO] starting ant 4 with config {localhost:52266 :52267 :52268 ./antfarm-data/renter renter siad [renter] 100000}
2018/05/25 11:58:35 [./antfarm-data/host1 balanceMaintainer INFO]: mined enough currency, stopping the miner
2018/05/25 11:58:40 error clearing upnp ports for ant: goupnp: SOAP request got HTTP 500 Internal Server Error: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns="urn:schemas-upnp-org:control-1-0"><errorCode>714</errorCode><errorDescription>NoSuchEntryInArray</errorDescription></UPnPError></detail></s:Fault></s:Body></s:Envelope>
2018/05/25 11:58:40 [INFO] [renter] [./antfarm-data/renter] Blocking until wallet is sufficiently full
Finished.  Running sia-antfarm with 5 ants.
2018/05/25 11:58:55 [./antfarm-data/host1 balanceMaintainer INFO]: not enough currency, starting the miner
2018/05/25 11:58:56 [./antfarm-data/host2 jobHost INFO]: succesfully performed host announcement
2018/05/25 11:59:10 [./antfarm-data/host2 balanceMaintainer INFO]: mined enough currency, stopping the miner
2018/05/25 11:59:15 [./antfarm-data/host3 balanceMaintainer INFO]: mined enough currency, stopping the miner
2018/05/25 11:59:15 [./antfarm-data/host3 jobHost INFO]: succesfully performed host announcement
2018/05/25 11:59:15 [./antfarm-data/host1 balanceMaintainer INFO]: mined enough currency, stopping the miner
2018/05/25 11:59:30 Ants split into multiple groups.
2018/05/25 11:59:30 Group  1
2018/05/25 11:59:30 localhost:52168
2018/05/25 11:59:30
2018/05/25 11:59:30 Group  2
2018/05/25 11:59:30 localhost:52181
2018/05/25 11:59:30 localhost:52205
2018/05/25 11:59:30 localhost:52236
2018/05/25 11:59:30
2018/05/25 11:59:30 Group  3
2018/05/25 11:59:30 localhost:52266
2018/05/25 11:59:50 [antfarm-data/ant397733575 SUCCESS] blockMining job succeeded
2018/05/25 11:59:50 Ants are synchronized. Block Height:  64
2018/05/25 12:00:00 [./antfarm-data/renter balanceMaintainer INFO]: mined enough currency, stopping the miner
2018/05/25 12:00:10 Ants split into multiple groups.
2018/05/25 12:00:10 Group  1
2018/05/25 12:00:10 localhost:52168
2018/05/25 12:00:10 localhost:52181
2018/05/25 12:00:10 localhost:52205
2018/05/25 12:00:10
2018/05/25 12:00:10 Group  2
2018/05/25 12:00:10 localhost:52236
2018/05/25 12:00:10 localhost:52266
2018/05/25 12:00:30 Ants are synchronized. Block Height:  84
2018/05/25 12:00:50 Ants are synchronized. Block Height:  90
2018/05/25 12:01:10 Ants are synchronized. Block Height:  98
roughpandaz commented 6 years ago

Additionally, how should I get this to run on AWS? I run the file with the command

go run sia-antfarm/main.go sia-antfarm/antfarm.go sia-antfarm/ant.go -config nebulous-configs/basic-renter-host.json

However, I get this output, even though I opened the specific ports and enabled outgoing and incoming TCP connections.

[INFO] starting ant 0 with config {localhost:45130 :34329 :41951 antfarm-data/ant579143336  siad [gateway miner] 0}
2018/05/25 15:48:15 error clearing upnp ports for ant: no UPnP-enabled gateway found
error creating antfarm: exec: "siad": executable file not found in $PATH
exit status 1
lukechampine commented 6 years ago

Hi @RongxinZhang,

no UPnP-enabled gateway found

this is more of a warning than an error. Sia will try to automatically forward the ports it needs, and it also uses UPnP to discover its external IP address if necessary. AWS (and most VPSs) don't sit behind a UPnP-enabled gateway, but their ports will be open so it's a non-issue. In the case of a local router, you can forward the ports manually and it should work fine.

2018/05/25 11:58:10 error clearing upnp ports for ant: goupnp: SOAP request got HTTP 500 Internal Server Error: ...NoSuchEntryInArray

this is another benign warning that you can ignore. It means that Sia tried to un-forward a port, but the port wasn't forwarded in the first place. Unfortunately UPnP is one of the worst protocols ever designed, so the error message is both extremely verbose and minimally helpful.

error creating antfarm: exec: "siad": executable file not found in $PATH

The antfarm uses whatever version of siad you installed. So you need to make sure you build siad before running the antfarm.

roughpandaz commented 6 years ago

@lukechampine Ahh ok, that's helpful!

roughpandaz commented 6 years ago

@lukechampine Regarding setting up a contract locally. After running the test net, I am able to ping the network using localhost:9980 to post a job via CURL

# post contract
curl -i -A "Sia-Agent" -X POST "localhost:9980/renter?funds=1000000000000000000000000000&period=4320"
# reponse
HTTP/1.1 204 No Content
Date: Sat, 26 May 2018 16:56:16 GMT

However, no miner seems to accept the contract. As a result I get the message

# post file
curl -i -A "Sia-Agent" -X POST localhost:9980/renter/upload/qux/bar.txt?source=/Users/roguepanda/Desktop/webdraft4c.jpg

# response
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
Date: Sat, 26 May 2018 17:03:22 GMT
Content-Length: 82

{"message":"upload failed: not enough contracts to upload file: got 0, needed 1"}

This is my config:

{
    "antconfigs":
    [
        {
            "jobs": [
                "gateway"
            ]
        },
        {
            "jobs": [
                "host"
            ],
            "desiredcurrency": 100000
        },
        {
            "Name": "renter",
            "jobs": [
                "renter"
            ],
            "desiredcurrency": 100000
        },
        {
            "apiaddr": "127.0.0.1:9980",
            "jobs": [
                "gateway",
                "miner"
            ]
        }
    ],
    "autoconnect": true
}
acejam commented 6 years ago

Bump to this. I'm also able to setup an Ant farm locally, but more than half the time contracts will never form. Blocks are being mined though, and I'm also able to mine blocks myself.

Is there a way to force or speed up contract creation?

roughpandaz commented 6 years ago

@acejam can you connect to the host's API and ping the /host route.

If the host's connectabilitystatus = false, then in the renter's host_db, this specific host's acceptingcontract = false. Then it is not possible to create a contract.

Basically, it looks like if you don't have a static IP which allows for incoming and outgoing connections then the renter will not form contracts with hosts.

If this is not the case, please correct me as this is what I have discovered so far.