Giter Site home page Giter Site logo

timestampvm's Introduction

Timestamp Virtual Machine

Lint+Test+Build

Avalanche is a network composed of multiple blockchains. Each blockchain is an instance of a Virtual Machine (VM), much like an object in an object-oriented language is an instance of a class. That is, the VM defines the behavior of the blockchain.

TimestampVM defines a blockchain that is a timestamp server. Each block in the blockchain contains the timestamp when it was created along with a 32-byte piece of data (payload). Each block’s timestamp is after its parent’s timestamp. This VM demonstrates capabilities of custom VMs and custom blockchains. For more information, see: Create a Virtual Machine

Running the VM

scripts/run.sh automatically installs [avalanchego], sets up a local network, and creates a timestampvm genesis file. To build and run E2E tests, you need to set the variable E2E before it: E2E=true ./scripts/run.sh 1.7.11

Note: The above script relies on ginkgo to run successfully. Ensure that $GOPATH/bin is part of your $PATH before running the script.

See tests/e2e to see how it's set up and how its client requests are made.

# to startup a local cluster (good for development)
cd ${HOME}/go/src/github.com/ava-labs/timestampvm
./scripts/run.sh 1.9.3

# to run full e2e tests and shut down cluster afterwards
cd ${HOME}/go/src/github.com/ava-labs/timestampvm
E2E=true ./scripts/run.sh 1.9.3

# inspect cluster endpoints when ready
cat /tmp/avalanchego-v1.9.3/output.yaml
<<COMMENT
endpoint: /ext/bc/2VCAhX6vE3UnXC6s1CBPE6jJ4c4cHWMfPgCptuWS59pQ9vbeLM
logsDir: ...
pid: 12811
uris:
- http://127.0.0.1:9650
- http://127.0.0.1:9652
- http://127.0.0.1:9654
- http://127.0.0.1:9656
- http://127.0.0.1:9658
network-runner RPC server is running on PID 66810...

use the following command to terminate:

pkill -P 66810 && kill -2 66810 && pkill -9 -f tGas3T58KzdjLHhBDMnH2TvrddhqTji5iZAMZ3RXs2NLpSnhH

# propose a block
curl -X POST --data '{
    "jsonrpc": "2.0",
    "method": "timestampvm.proposeBlock",
    "params":{
        "data":"0x01020304000000000000000000000000000000000000000000000000000000003f004e9c"
    },
    "id": 1
}' -H 'content-type:application/json;' http://127.0.0.1:9652/ext/bc/2W3Gn3E3xKSeHQZP47iybpgH6pk3JRWbNQs9P2FrKvXcHSNteB
<<COMMENT
{"jsonrpc":"2.0","result":{"Success":true},"id":1}
COMMENT

# view last accepted block
curl -X POST --data '{
    "jsonrpc": "2.0",
    "method": "timestampvm.getBlock",
    "params":{},
    "id": 1
}' -H 'content-type:application/json;' http://127.0.0.1:9652/ext/bc/2W3Gn3E3xKSeHQZP47iybpgH6pk3JRWbNQs9P2FrKvXcHSNteB
<<COMMENT
{"jsonrpc":"2.0","result":{"timestamp":"1668475950","data":"0x01020304000000000000000000000000000000000000000000000000000000003f004e9c","height":"1","id":"2RbyqtZcr8DWnxWjD2jLaPUsjd2cxMFbjz1kmJjR7gDpp3txvz","parentID":"SdVstz8FpkYxsneD2XQDk2CK7d1EBe4YVqkhftgbvUiyFfeHJ"},"id":1}
COMMENT

# terminate cluster
pkill -P 66810 && kill -2 66810 && pkill -9 -f tGas3T58KzdjLHhBDMnH2TvrddhqTji5iZAMZ3RXs2NLpSnhH

Load Testing the VM

Because TimestampVM is such a lightweight Virtual Machine, it is a great candidate for testing the raw performance of the ProposerVM wrapper in AvalancheGo.

To kickoff a load test, all you need to do is run the following command:

./scripts/tests.load.sh 1.9.3

This will automatically:

  • disable all rate limiting rules in AvalancheGo
  • activate the ProposerVM immediately (usually activates after 5 minutes on a new Subnet)
  • set the ProposerVM block timer to have 0 delay (generate blocks as fast as possible)

When running, you'll see a set of logs printed out indicating the current number of blocks per second generated and finalized on a local network:

INFO[11-18|09:19:58] Stats                                    height=0 avg bps=0.000 last bps=0.000
INFO[11-18|09:20:01] Stats                                    height=261 avg bps=86.795 last bps=87.000
INFO[11-18|09:20:04] Stats                                    height=597 avg bps=99.372 last bps=112.000
INFO[11-18|09:20:07] Stats                                    height=942 avg bps=104.566 last bps=115.000
INFO[11-18|09:20:10] Stats                                    height=1291 avg bps=107.493 last bps=116.333
INFO[11-18|09:20:13] Stats                                    height=1634 avg bps=108.854 last bps=114.333
INFO[11-18|09:20:16] Stats                                    height=1976 avg bps=109.664 last bps=114.000
INFO[11-18|09:20:19] Stats                                    height=2308 avg bps=109.804 last bps=110.667
INFO[11-18|09:20:22] Stats                                    height=2636 avg bps=109.742 last bps=109.333
INFO[11-18|09:20:25] Stats                                    height=2978 avg bps=110.213 last bps=114.000
INFO[11-18|09:20:28] Stats                                    height=3318 avg bps=110.512 last bps=113.333
INFO[11-18|09:20:31] Stats                                    height=3649 avg bps=110.489 last bps=110.333
INFO[11-18|09:20:34] Stats                                    height=3987 avg bps=110.667 last bps=112.667
INFO[11-18|09:20:37] Stats                                    height=4320 avg bps=110.691 last bps=111.000
INFO[11-18|09:20:40] Stats                                    height=4653 avg bps=110.711 last bps=111.000
INFO[11-18|09:20:43] Stats                                    height=4974 avg bps=110.453 last bps=107.000
INFO[11-18|09:20:46] Stats                                    height=5304 avg bps=110.423 last bps=110.000
INFO[11-18|09:20:49] Stats                                    height=5636 avg bps=110.434 last bps=110.667
INFO[11-18|09:20:52] Stats                                    height=5950 avg bps=110.101 last bps=104.667
INFO[11-18|09:20:55] Stats                                    height=6236 avg bps=109.317 last bps=95.333
INFO[11-18|09:20:58] Stats                                    height=6552 avg bps=109.116 last bps=105.333
INFO[11-18|09:21:01] Stats                                    height=6876 avg bps=109.061 last bps=108.000
INFO[11-18|09:21:04] Stats                                    height=7210 avg bps=109.163 last bps=111.333
INFO[11-18|09:21:07] Stats                                    height=7499 avg bps=108.574 last bps=96.333
INFO[11-18|09:21:10] Stats                                    height=7787 avg bps=108.049 last bps=96.000
INFO[11-18|09:21:13] Stats                                    height=8119 avg bps=108.152 last bps=110.667
INFO[11-18|09:21:16] Stats                                    height=8449 avg bps=108.222 last bps=110.000
INFO[11-18|09:21:19] Stats                                    height=8779 avg bps=108.279 last bps=110.000
INFO[11-18|09:21:22] Stats                                    height=9107 avg bps=108.315 last bps=109.333
INFO[11-18|09:21:25] Stats                                    height=9437 avg bps=108.372 last bps=110.000
INFO[11-18|09:21:28] Stats                                    height=9757 avg bps=108.315 last bps=106.667
INFO[11-18|09:21:31] Stats                                    height=10069 avg bps=108.175 last bps=104.000
INFO[11-18|09:21:34] Stats                                    height=10401 avg bps=108.242 last bps=110.667

timestampvm's People

Contributors

aaronbuchwald avatar ceyonur avatar cgcardona avatar cinterloper avatar connorbode avatar domdu avatar exdx avatar felipemadero avatar gyuho avatar hexfusion avatar patrick-ogrady avatar stephenbuttolph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

timestampvm's Issues

RPC error: Deadline exceeded @avalanchego v1.9.7

Using Avalanche-CLI, I tried to spin up a subnet with customVM. Using avalanchego v.1.9.7, I tried to deploy the subnet with the following command: avalanche subnet deploy timestampvm --avalanchego-version v1.9.7

However, the network could not be started, and I got the following error: Error: failed to query network health: rpc error: code = DeadlineExceeded desc = context deadline exceeded after waiting for a few minutes.

The network were started with ./scripts/run.sh and passed all the tests, but I do not see how the command I used would not spin up the subnet.

Ctrl-C does not kill load test script

Bug

When running the load test script with:

./scripts/tests.load.sh v1.9.3

I hit ctrl-c and get the following output:

[node5] INFO [11-30|17:53:45.018] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:802: Waiting for trie re-journal to complete 
[node5] INFO [11-30|17:53:45.018] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:805: Blockchain stopped 
[11-30|17:53:45.018] WARN server/server.go:187 root context is done
[node4] {"@level":"trace","@message":"plugin received interrupt signal, ignoring","@timestamp":"2022-11-30T17:53:45.008246-05:00","count":1}
[11-30|17:53:45.022] WARN server/server.go:195 closed gRPC server
[11-30|17:53:45.022] WARN server/server.go:197 gRPC terminated
  [FAILED] in [AfterSuite] - /Users/aaronbuchwald/go/src/github.com/ava-labs/timestampvm/tests/load/load_test.go:283 @ 11/30/22 17:53:45.023
[AfterSuite] [FAILED] [0.002 seconds]
[AfterSuite] 
/Users/aaronbuchwald/go/src/github.com/ava-labs/timestampvm/tests/load/load_test.go:278

  [FAILED] Expected
      <*status.Error | 0xc000011278>: {
          s: {
              s: {
                  state: {
                      NoUnkeyedLiterals: {},
                      DoNotCompare: [],
                      DoNotCopy: [],
                      atomicMessageInfo: nil,
                  },
                  sizeCache: 0,
                  unknownFields: nil,
                  Code: 14,
                  Message: "error reading from server: read tcp 127.0.0.1:59097->127.0.0.1:12342: read: connection reset by peer",
                  Details: nil,
              },
          },
      }
  to be nil
  In [AfterSuite] at: /Users/aaronbuchwald/go/src/github.com/ava-labs/timestampvm/tests/load/load_test.go:283 @ 11/30/22 17:53:45.023
------------------------------

Summarizing 2 Failures:
  [INTERRUPTED] [ProposeBlock] [It] create new blocks
  /Users/aaronbuchwald/go/src/github.com/ava-labs/timestampvm/tests/load/load_test.go:304
  [FAIL] [AfterSuite] 
  /Users/aaronbuchwald/go/src/github.com/ava-labs/timestampvm/tests/load/load_test.go:283

Ran 2 of 2 Specs in 343.844 seconds
FAIL! - Interrupted by User -- 1 Passed | 1 Failed | 0 Pending | 0 Skipped
--- FAIL: TestLoad (343.84s)
FAIL
[node4] INFO [11-30|17:53:45.022] <C Chain> github.com/ava-labs/coreth/core/tx_pool.go:456: Transaction pool stopped 
[node4] INFO [11-30|17:53:45.029] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:774: Closing quit channel 
[node4] INFO [11-30|17:53:45.029] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:777: Stopping Acceptor 
[node4] INFO [11-30|17:53:45.029] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:780: Acceptor queue drained t="26.514µs"
[node4] INFO [11-30|17:53:45.030] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:782: Shutting down state manager 
[node4] INFO [11-30|17:53:45.030] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:787: State manager shut down t=974ns
[node4] INFO [11-30|17:53:45.030] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:794: Shutting down sender cacher 
[node4] INFO [11-30|17:53:45.030] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:798: Closing scope 
[node4] INFO [11-30|17:53:45.030] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:802: Waiting for trie re-journal to complete 
[node4] INFO [11-30|17:53:45.030] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:805: Blockchain stopped 
[node3] 2022-11-30T17:53:45.032-0500 [INFO]  plugin process exited: path=/tmp/timestampvm-load/avalanchego/build/plugins/tGas3T58KzdjLHhBDMnH2TvrddhqTji5iZAMZ3RXs2NLpSnhH pid=97922
[node5] 2022-11-30T17:53:45.032-0500 [INFO]  plugin process exited: path=/tmp/timestampvm-load/avalanchego/build/plugins/tGas3T58KzdjLHhBDMnH2TvrddhqTji5iZAMZ3RXs2NLpSnhH pid=97923
[node2] 2022-11-30T17:53:45.032-0500 [INFO]  plugin process exited: path=/tmp/timestampvm-load/avalanchego/build/plugins/tGas3T58KzdjLHhBDMnH2TvrddhqTji5iZAMZ3RXs2NLpSnhH pid=97924
[node1] INFO [11-30|17:53:45.022] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:774: Closing quit channel 
[node1] INFO [11-30|17:53:45.034] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:777: Stopping Acceptor 
[node1] INFO [11-30|17:53:45.034] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:780: Acceptor queue drained t="4.119µs"
[node1] INFO [11-30|17:53:45.034] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:782: Shutting down state manager 
[node1] INFO [11-30|17:53:45.034] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:787: State manager shut down t="1.121µs"
[node1] INFO [11-30|17:53:45.034] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:794: Shutting down sender cacher 
[node1] INFO [11-30|17:53:45.034] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:798: Closing scope 
[node1] INFO [11-30|17:53:45.034] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:802: Waiting for trie re-journal to complete 
[node1] INFO [11-30|17:53:45.034] <C Chain> github.com/ava-labs/coreth/core/blockchain.go:805: Blockchain stopped 
[node4] 2022-11-30T17:53:45.060-0500 [INFO]  plugin process exited: path=/tmp/timestampvm-load/avalanchego/build/plugins/tGas3T58KzdjLHhBDMnH2TvrddhqTji5iZAMZ3RXs2NLpSnhH pid=97921                                                                    
aaronbuchwald@aarons-mbp-2 timestampvm % [node1] 2022-11-30T17:53:45.122-0500 [INFO]  plugin process exited: path=/tmp/timestampvm-load/avalanchego/build/plugins/tGas3T58KzdjLHhBDMnH2TvrddhqTji5iZAMZ3RXs2NLpSnhH pid=97920
terminated network %!s(<nil>)
[11-30|17:53:45.148] WARN server/server.go:218 network stopped
[11-30|17:53:45.148] WARN server/server.go:105 closed server


which then hangs here until hitting ctrl-c a second time.

Expected Behavior

Hitting ctrl-c once should kill the load testing script instead of hanging.

Can't propose block

Non-static API calls are not recognized:

curl -X POST --data '{
                                   "jsonrpc": "2.0",
                                   "method": "timestampvm.proposeBlock",
                                   "params":{
                                       "data":"SkB92YpWm4Q2iPnLGCuDPZPgUQMxajqQQuz91oi3xD984f8r"
                                   },
                                   "id": 1
                               }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/vm/timestampvm
{"jsonrpc":"2.0","error":{"code":-32000,"message":"rpc: can't find method \"timestampvm.ProposeBlock\"","data":null},"id":1}

Static calls work fine:

curl -X POST --data '{
                                   "jsonrpc": "2.0",
                                   "method": "timestampvm.encode",
                                   "params":{
                                       "data":"SkB92YpWm4Q2iPnLGCuDPZPgUQMxajqQQuz91oi3xD984f8r"
                                   },
                                   "id": 1
                               }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/vm/timestampvm
{"jsonrpc":"2.0","result":{"bytes":"M2NcATdFX63NpvNFE5pRgLXY1DLgo7oLVNKYNzTVEswz6YEALQ5EvzXeoR6sqzBJhjUo84t","encoding":"cb58"},"id":1}

The tutorial shows to use an /ext/bc address (typo?), but I've tried all the endpoints listed by the node on startup and none recognize the method. From the tutorial:

curl -X POST --data '{
    "jsonrpc": "2.0",
    "method": "timestampvm.proposeBlock",
    "params":{
        "data":"SkB92YpWm4Q2iPnLGCuDPZPgUQMxajqQQuz91oi3xD984f8r"
    },
    "id": 1
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/sw813hGSWH8pdU9uzaYy9fCtYFfY7AjDd2c9rm64SbApnvjmk

If that's not a typo, it would help to mention where to find the right endpoint vs. just using a hardcoded value in the sample call, i.e., sw813hGSWH8pdU9uzaYy9fCtYFfY7AjDd2c9rm64SbApnvjmk.

method timestampvm.proposeBlock does not exist/is not available

I was following through the Avalanche docs to set up my custom VM. I set up a local network (AvalancheGo v.1.9.14), and spinned up a subnet called timestampvm (I forked the timestampvm repository). The subnet was spinned up successfull with a custom VM with the right VMID. However, whenever I sent a request to one of the nodes, I kept getting the error:

{"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"the method timestampvm.proposeBlock does not exist/is not available"}}

Any ideas as to why this is happening?

scripts/run.sh does not work

Currently the run script does not work on timestampvm:

Using the main branch and running

./scripts/run.sh v1.9.3

I get the following output:

Running with:
VERSION: v1.9.3
MODE: run
downloading avalanchego v1.9.3 at https://github.com/ava-labs/avalanchego/releases/download/vv1.9.3/avalanchego-macos-vv1.9.3.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100     9  100     9    0     0     57      0 --:--:-- --:--:-- --:--:--    60
extracting downloaded avalanchego
Archive:  /tmp/avalanchego.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of /tmp/avalanchego.zip or
        /tmp/avalanchego.zip.zip, and cannot find /tmp/avalanchego.zip.ZIP, period.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.