Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 4d9cb73

Browse files
Merge pull request #33 from ava-labs/cleanup-client
Lifeline + Basic client cleanup
2 parents b4cde22 + a99a3fc commit 4d9cb73

File tree

14 files changed

+395
-413
lines changed

14 files changed

+395
-413
lines changed

README.md

Lines changed: 163 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ uris:
6060
COMMENT
6161

6262
# ping the local cluster
63-
curl -X POST --data '{
63+
curl --location --request POST 'http://localhost:61858/ext/bc/BJfusM2TpHCEfmt5i7qeE1MwVCbw5jU1TcZNz8MYUwG1PGYRL/public' \
64+
--header 'Content-Type: application/json' \
65+
--data-raw '{
6466
"jsonrpc": "2.0",
6567
"method": "quarkvm.ping",
6668
"params":{},
6769
"id": 1
68-
}' -H 'content-type:application/json;' 127.0.0.1:56239/ext/bc/2VCAhX6vE3UnXC6s1CBPE6jJ4c4cHWMfPgCptuWS59pQ9vbeLM
70+
}'
6971
<<COMMENT
7072
{"jsonrpc":"2.0","result":{"success":true},"id":1}
7173
COMMENT
@@ -74,22 +76,163 @@ COMMENT
7476
kill 12811
7577
```
7678

77-
## Claim a Prefix (work done automatically)
79+
# CLI Usage
80+
## Create Genesis
81+
```bash
82+
./build/quark-cli genesis
83+
```
84+
85+
## Create Private Key
86+
```bash
87+
./build/quark-cli create
88+
```
89+
90+
## Claim a Prefix
91+
```bash
92+
./build/quark-cli \
93+
--private-key-file .quark-cli-pk \
94+
--endpoint http://localhost:61858/ext/bc/BJfusM2TpHCEfmt5i7qeE1MwVCbw5jU1TcZNz8MYUwG1PGYRL \
95+
claim patrick.avax
96+
97+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/201]... (elapsed=1.01s, est. remaining=1m54.3s, threads=16)
98+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/3329621]... (elapsed=3.01s, est. remaining=1m52.3s, threads=16)
99+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/6640466]... (elapsed=5.01s, est. remaining=1m50.3s, threads=16)
100+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/9938320]... (elapsed=7.01s, est. remaining=1m48.3s, threads=16)
101+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/13222800]... (elapsed=9.01s, est. remaining=1m46.3s, threads=16)
102+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/16473949]... (elapsed=11.01s, est. remaining=1m44.3s, threads=16)
103+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/19307265]... (elapsed=13.01s, est. remaining=1m42.3s, threads=16)
104+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/22151737]... (elapsed=15.01s, est. remaining=1m40.3s, threads=16)
105+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/25580779]... (elapsed=17.01s, est. remaining=1m38.3s, threads=16)
106+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/28485504]... (elapsed=19.01s, est. remaining=1m36.3s, threads=16)
107+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/31685345]... (elapsed=21.01s, est. remaining=1m34.3s, threads=16)
108+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/34616110]... (elapsed=23.01s, est. remaining=1m32.3s, threads=16)
109+
mining in progress[ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh/37668727]... (elapsed=25.01s, est. remaining=1m30.3s, threads=16)
110+
mining complete[40596778] (difficulty=188, surplus=541200, elapsed=26.97s)
111+
issuing tx 7Y5voKiHGvytF7ddroV7UvgW8LgmxPR7EzZSyJY1MwQJ4yC9x (fee units=6150, load units=50, difficulty=188, blkID=ShWhojqb9FYqf2cWTYWauv1QFuT6igUxLjqATntvq3E52kdLh)
112+
issued transaction 7Y5voKiHGvytF7ddroV7UvgW8LgmxPR7EzZSyJY1MwQJ4yC9x (now polling)
113+
transaction 7Y5voKiHGvytF7ddroV7UvgW8LgmxPR7EzZSyJY1MwQJ4yC9x confirmed
114+
raw prefix M9Jh5DMRXwMwaTHciFLVAMpc9dZKFpuGE: units=1 expiry=2022-02-09 02:17:33 -0800 PST (719h59m58.807801s remaining)
115+
```
116+
117+
## Set Key in Prefix
118+
```bash
119+
./build/quark-cli \
120+
--private-key-file .quark-cli-pk \
121+
--endpoint http://localhost:61858/ext/bc/BJfusM2TpHCEfmt5i7qeE1MwVCbw5jU1TcZNz8MYUwG1PGYRL \
122+
set patrick.avax/twitter @_patrickogrady
123+
124+
mining in progress[2QsEbN4VgFjeMMfxU1T9KWUFMLtyTpYT7Ud8fw4kZ7hZfMMWhA/37]... (elapsed=1.01s, threads=16)
125+
mining complete[1145609] (difficulty=165, surplus=715, elapsed=1.76s)
126+
issuing tx APWDpcgjUcDDP8P4L97x3BbKkvJ4NzZfESXc2AcNjQV99aRqw (fee units=11, load units=11, difficulty=165, blkID=2QsEbN4VgFjeMMfxU1T9KWUFMLtyTpYT7Ud8fw4kZ7hZfMMWhA)
127+
issued transaction APWDpcgjUcDDP8P4L97x3BbKkvJ4NzZfESXc2AcNjQV99aRqw (now polling)
128+
transaction APWDpcgjUcDDP8P4L97x3BbKkvJ4NzZfESXc2AcNjQV99aRqw confirmed
129+
raw prefix M9Jh5DMRXwMwaTHciFLVAMpc9dZKFpuGE: units=2 expiry=2022-01-25 02:18:47 -0800 PST (359h59m58.948798s remaining)
130+
```
131+
132+
## Get Key in Preifx
133+
```bash
134+
./build/quark-cli \
135+
--private-key-file .quark-cli-pk \
136+
--endpoint http://localhost:61858/ext/bc/BJfusM2TpHCEfmt5i7qeE1MwVCbw5jU1TcZNz8MYUwG1PGYRL \
137+
get patrick.avax/twitter
138+
139+
range success 1 key-values
140+
key: "twitter", value: "@_patrickogrady"
141+
```
142+
143+
## Delete Key in Preifx
144+
```bash
145+
./build/quark-cli \
146+
--private-key-file .quark-cli-pk \
147+
--endpoint http://localhost:61858/ext/bc/BJfusM2TpHCEfmt5i7qeE1MwVCbw5jU1TcZNz8MYUwG1PGYRL \
148+
delete patrick.avax/twitter
149+
150+
mining in progress[g5rmmSRrCMZDUsg5KBzNR4wpeX6Ph6xaXoNCPwUWj7xHM7epD/333]... (elapsed=1.01s, threads=16)
151+
mining complete[222163] (difficulty=127, surplus=297, elapsed=1.16s)
152+
issuing tx 2AmF6zY1mTdniwXrifoKCfzPGEqrKyJv21S8k5gSa1MYbhFR3h (fee units=11, load units=11, difficulty=127, blkID=g5rmmSRrCMZDUsg5KBzNR4wpeX6Ph6xaXoNCPwUWj7xHM7epD)
153+
issued transaction 2AmF6zY1mTdniwXrifoKCfzPGEqrKyJv21S8k5gSa1MYbhFR3h (now polling)
154+
transaction 2AmF6zY1mTdniwXrifoKCfzPGEqrKyJv21S8k5gSa1MYbhFR3h confirmed
155+
raw prefix M9Jh5DMRXwMwaTHciFLVAMpc9dZKFpuGE: units=1 expiry=2022-02-09 02:20:55 -0800 PST (719h59m58.687729s remaining)
156+
```
78157

158+
## Extend Prefix Life
79159
```bash
80160
./build/quark-cli \
81161
--private-key-file .quark-cli-pk \
82-
--url http://127.0.0.1:9650 \
83-
--endpoint /ext/bc/2VCAhX6vE3UnXC6s1CBPE6jJ4c4cHWMfPgCptuWS59pQ9vbeLM \
84-
claim pat
85-
86-
>>>>>
87-
creating requester with URL http://127.0.0.1:9650 and endpoint "/ext/bc/2VCAhX6vE3UnXC6s1CBPE6jJ4c4cHWMfPgCptuWS59pQ9vbeLM"
88-
Submitting tx NpfRjXRGRCXGxfqq6vcvH3GAm3yijJyxYD7QBxQFDS6YvSnXw with BlockID (zgvHpznxkG7xAh2qgsQFVkrioB4ENdKYfum6KWe6rZGiuzdPf): &{0xc00011a0c8 [175 87 123 222 38 232 10 27 198 13 215 107 60 56 102 21 11 12 195 39 191 122 160 156 155 11 183 164 202 22 22 76 231 28 232 58 18 187 198 249 170 168 232 227 43 85 90 54 94 76 49 184 59 9 194 205 222 162 20 67 208 185 115 12] 0}
89-
issued transaction NpfRjXRGRCXGxfqq6vcvH3GAm3yijJyxYD7QBxQFDS6YvSnXw (success true)
90-
polling transaction "NpfRjXRGRCXGxfqq6vcvH3GAm3yijJyxYD7QBxQFDS6YvSnXw"
91-
confirmed transaction "NpfRjXRGRCXGxfqq6vcvH3GAm3yijJyxYD7QBxQFDS6YvSnXw"
92-
prefix pat info &{Owner:0xc00011dd70 LastUpdated:1638591044 Expiry:1638591074 Keys:1}
162+
--endpoint http://localhost:61858/ext/bc/BJfusM2TpHCEfmt5i7qeE1MwVCbw5jU1TcZNz8MYUwG1PGYRL \
163+
lifeline patrick.avax
164+
165+
mining in progress[2ty1GmQAatedGd3CeUXzj5YUYVaqeMawpvCRPxqCf12u7fNfM/39]... (elapsed=1.01s, threads=16)
166+
mining complete[469870] (difficulty=169, surplus=690, elapsed=1.31s)
167+
issuing tx 2bJPjSWyr6NoDUE9ZyyamDetjNYDQ87G4dtZnT3LVf4uGYtFtU (fee units=10, load units=10, difficulty=169, blkID=2ty1GmQAatedGd3CeUXzj5YUYVaqeMawpvCRPxqCf12u7fNfM)
168+
issued transaction 2bJPjSWyr6NoDUE9ZyyamDetjNYDQ87G4dtZnT3LVf4uGYtFtU (now polling)
169+
transaction 2bJPjSWyr6NoDUE9ZyyamDetjNYDQ87G4dtZnT3LVf4uGYtFtU confirmed
170+
raw prefix M9Jh5DMRXwMwaTHciFLVAMpc9dZKFpuGE: units=1 expiry=2022-02-09 04:07:07 -0800 PST (721h44m47.312056s remaining)
171+
```
172+
173+
# HTTP Examples
174+
## Get Prefix Info
175+
_cGF0cmljay5hdmF4 is "patrick.avax" in base64_
176+
```bash
177+
curl --location --request POST 'http://localhost:61858/ext/bc/BJfusM2TpHCEfmt5i7qeE1MwVCbw5jU1TcZNz8MYUwG1PGYRL/public' \
178+
--header 'Content-Type: application/json' \
179+
--data-raw '{
180+
"jsonrpc": "2.0",
181+
"method": "quarkvm.prefixInfo",
182+
"params":{
183+
"prefix":"cGF0cmljay5hdmF4"
184+
},
185+
"id": 1
186+
}'
187+
188+
{
189+
"jsonrpc": "2.0",
190+
"result": {
191+
"info": {
192+
"owner": [
193+
3,
194+
74,
195+
255,
196+
247,
197+
51,
198+
219,
199+
231,
200+
3,
201+
243,
202+
231,
203+
100,
204+
99,
205+
245,
206+
34,
207+
43,
208+
222,
209+
16,
210+
61,
211+
202,
212+
99,
213+
39,
214+
113,
215+
85,
216+
197,
217+
4,
218+
185,
219+
122,
220+
214,
221+
117,
222+
141,
223+
45,
224+
98,
225+
196
226+
],
227+
"created": 1641809853,
228+
"lastUpdated": 1641810055,
229+
"expiry": 1644408427,
230+
"units": 1,
231+
"rawPrefix": "M9Jh5DMRXwMwaTHciFLVAMpc9dZKFpuGE"
232+
}
233+
},
234+
"id": 1
235+
}
93236
```
94237

95238
# Difficulty Estiamtes
@@ -104,10 +247,10 @@ goos: darwin
104247
goarch: amd64
105248
pkg: github.com/ava-labs/quarkvm/pow
106249
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
107-
BenchmarkDifficulty1-16 1145233 1047 ns/op
108-
BenchmarkDifficulty10-16 113216 10335 ns/op
109-
BenchmarkDifficulty50-16 23011 52336 ns/op
110-
BenchmarkDifficulty100-16 11540 102029 ns/op
111-
BenchmarkDifficulty500-16 1962 535265 ns/op
112-
BenchmarkDifficulty1000-16 1132 1082758 ns/op
250+
BenchmarkDifficulty1-16 1300 921956 ns/op
251+
BenchmarkDifficulty10-16 100 11083185 ns/op
252+
BenchmarkDifficulty50-16 100 50243796 ns/op
253+
BenchmarkDifficulty100-16 12 84529354 ns/op
254+
BenchmarkDifficulty500-16 7 251526615 ns/op
255+
BenchmarkDifficulty1000-16 7 571905766 ns/op
113256
```

chain/lifeline_tx.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ func addLife(db database.KeyValueReaderWriter, prefix []byte) error {
2424
}
2525
// Lifeline spread across all units
2626
lastExpiry := i.Expiry
27-
prefixPenalty := prefixUnits(prefix) / PrefixRenewalDiscount
28-
if prefixPenalty < 1 { // avoid division by 0
29-
prefixPenalty = 1
30-
}
31-
32-
i.Expiry += ExpiryTime / i.Units / prefixPenalty
27+
i.Expiry += ExpiryTime / i.Units
3328
return PutPrefixInfo(db, prefix, i, lastExpiry)
3429
}
3530

3631
func (l *LifelineTx) Execute(db database.Database, blockTime uint64) error {
3732
return addLife(db, l.Prefix)
3833
}
3934

35+
func (l *LifelineTx) FeeUnits() uint64 {
36+
prefixUnits := prefixUnits(l.Prefix) / PrefixRenewalDiscount
37+
return l.LoadUnits() + prefixUnits
38+
}
39+
4040
func (l *LifelineTx) Copy() UnsignedTransaction {
4141
return &LifelineTx{
4242
BaseTx: l.BaseTx.Copy(),

client/client.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package client
77
import (
88
"context"
99
"fmt"
10-
"strings"
1110
"time"
1211

1312
"github.com/ava-labs/avalanchego/ids"
@@ -47,14 +46,10 @@ type Client interface {
4746
}
4847

4948
// New creates a new client object.
50-
func New(uri string, endpoint string, reqTimeout time.Duration) Client {
51-
// TODO: automatically append public/private based on method
52-
if !strings.HasPrefix(endpoint, "/") {
53-
endpoint = "/" + endpoint
54-
}
49+
func New(uri string, reqTimeout time.Duration) Client {
5550
req := rpc.NewEndpointRequester(
5651
uri,
57-
endpoint,
52+
vm.PublicEndpoint,
5853
"quarkvm",
5954
reqTimeout,
6055
)

cmd/quarkcli/claim/claim.go renamed to cmd/quarkcli/cmd/claim.go

Lines changed: 10 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,25 @@
11
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
22
// See the file LICENSE for licensing terms.
33

4-
package claim
4+
package cmd
55

66
import (
77
"bytes"
88
"context"
99
"fmt"
1010
"os"
11-
"strings"
12-
"time"
1311

14-
"github.com/fatih/color"
1512
"github.com/spf13/cobra"
1613

1714
"github.com/ava-labs/quarkvm/chain"
1815
"github.com/ava-labs/quarkvm/client"
19-
"github.com/ava-labs/quarkvm/cmd/quarkcli/create"
2016
"github.com/ava-labs/quarkvm/parser"
2117
)
2218

23-
func init() {
24-
cobra.EnablePrefixMatching = true
25-
}
26-
27-
var (
28-
privateKeyFile string
29-
url string
30-
endpoint string
31-
requestTimeout time.Duration
32-
prefixInfo bool
33-
)
34-
35-
// NewCommand implements "quark-cli claim" command.
36-
func NewCommand() *cobra.Command {
37-
cmd := &cobra.Command{
38-
Use: "claim [options] <prefix>",
39-
Short: "Claims the given prefix",
40-
Long: `
19+
var claimCmd = &cobra.Command{
20+
Use: "claim [options] <prefix>",
21+
Short: "Claims the given prefix",
22+
Long: `
4123
Claims the given prefix by issuing claim transaction
4224
with the prefix information.
4325
@@ -65,44 +47,12 @@ success
6547
COMMENT
6648
6749
`,
68-
RunE: claimFunc,
69-
}
70-
cmd.PersistentFlags().StringVar(
71-
&privateKeyFile,
72-
"private-key-file",
73-
".quark-cli-pk",
74-
"private key file path",
75-
)
76-
cmd.PersistentFlags().StringVar(
77-
&url,
78-
"url",
79-
"http://127.0.0.1:9650",
80-
"RPC URL for VM",
81-
)
82-
cmd.PersistentFlags().StringVar(
83-
&endpoint,
84-
"endpoint",
85-
"",
86-
"RPC endpoint for VM",
87-
)
88-
cmd.PersistentFlags().DurationVar(
89-
&requestTimeout,
90-
"request-timeout",
91-
30*time.Second,
92-
"timeout for transaction issuance and confirmation",
93-
)
94-
cmd.PersistentFlags().BoolVar(
95-
&prefixInfo,
96-
"prefix-info",
97-
true,
98-
"'true' to print out the prefix owner information",
99-
)
100-
return cmd
50+
RunE: claimFunc,
10151
}
10252

10353
// TODO: move all this to a separate client code
10454
func claimFunc(cmd *cobra.Command, args []string) error {
105-
priv, err := create.LoadPK(privateKeyFile)
55+
priv, err := LoadPK(privateKeyFile)
10656
if err != nil {
10757
return err
10858
}
@@ -112,12 +62,7 @@ func claimFunc(cmd *cobra.Command, args []string) error {
11262
}
11363

11464
pfx := getClaimOp(args)
115-
116-
if !strings.HasPrefix(endpoint, "/") {
117-
endpoint = "/" + endpoint
118-
}
119-
color.Blue("creating requester with URL %s and endpoint %q for prefix %q", url, endpoint, pfx)
120-
cli := client.New(url, endpoint, requestTimeout)
65+
cli := client.New(uri, requestTimeout)
12166

12267
utx := &chain.ClaimTx{
12368
BaseTx: &chain.BaseTx{
@@ -126,13 +71,8 @@ func claimFunc(cmd *cobra.Command, args []string) error {
12671
},
12772
}
12873

129-
opts := []client.OpOption{client.WithPollTx()}
130-
if prefixInfo {
131-
opts = append(opts, client.WithPrefixInfo(pfx))
132-
}
133-
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
134-
_, err = client.MineSignIssueTx(ctx, cli, utx, priv, opts...)
135-
cancel()
74+
opts := []client.OpOption{client.WithPollTx(), client.WithPrefixInfo(pfx)}
75+
_, err = client.MineSignIssueTx(context.Background(), cli, utx, priv, opts...)
13676
return err
13777
}
13878

0 commit comments

Comments
 (0)