Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ KVVM is served over RPC with [go-plugin](https://github.com/hashicorp/go-plugin)
# Features
TODO: Extend on
* PoW Transactions (no tokens)
* No Nonces (replay protection from blockID + txID)
* Prefixes (address prefixes reserved)
* Hashed Value Keys
* Prefix Expiry (based on weight of all key-values)
* Load Units vs Fee Units
* Lifeline Rewards (why run a node -> don't need to mine)
* Block Value Reuse

# RPC
## /public
Expand Down Expand Up @@ -72,6 +74,21 @@ curl --location --request POST 'http://localhost:61858/ext/bc/BJfusM2TpHCEfmt5i7
{"jsonrpc":"2.0","result":{"success":true},"id":1}
COMMENT

# resolve a path
curl --location --request POST 'http://localhost:61858/ext/bc/BJfusM2TpHCEfmt5i7qeE1MwVCbw5jU1TcZNz8MYUwG1PGYRL/public' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "quarkvm.resolve",
"params":{
"path": "patrick.avax/twitter"
},
"id": 1
}'
<<COMMENT
{"jsonrpc":"2.0","result":{"exists":true, "value":"QF9wYXRyaWNrb2dyYWR5"},"id":1}
COMMENT

# to terminate the cluster
kill 12811
```
Expand Down
9 changes: 9 additions & 0 deletions chain/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ func ParseBlock(
if _, err := Unmarshal(source, blk); err != nil {
return nil, err
}
return ParseStatefulBlock(blk, source, status, vm)
}

func ParseStatefulBlock(
blk *StatefulBlock,
source []byte,
status choices.Status,
vm VM,
) (*StatelessBlock, error) {
b := &StatelessBlock{
StatefulBlock: blk,
t: time.Unix(blk.Tmstmp, 0),
Expand Down
4 changes: 3 additions & 1 deletion chain/claim_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"bytes"

"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/crypto"

"github.com/ava-labs/quarkvm/parser"
)

Expand All @@ -17,7 +19,7 @@ type ClaimTx struct {
*BaseTx `serialize:"true" json:"baseTx"`
}

func (c *ClaimTx) Execute(db database.Database, blockTime uint64) error {
func (c *ClaimTx) Execute(db database.Database, blockTime uint64, _ ids.ID) error {
// Restrict address prefix to be owned by pk
// [33]byte prefix is reserved for pubkey
if len(c.Prefix) == crypto.SECP256K1RPKLen && !bytes.Equal(c.Sender[:], c.Prefix) {
Expand Down
3 changes: 2 additions & 1 deletion chain/claim_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/crypto"
)

Expand Down Expand Up @@ -79,7 +80,7 @@ func TestClaimTx(t *testing.T) {
t.Fatalf("#%d: ExpireNext errored %v", i, err)
}
}
err := tv.tx.Execute(db, uint64(tv.blockTime))
err := tv.tx.Execute(db, uint64(tv.blockTime), ids.ID{})
if !errors.Is(err, tv.err) {
t.Fatalf("#%d: tx.Execute err expected %v, got %v", i, tv.err, err)
}
Expand Down
3 changes: 2 additions & 1 deletion chain/lifeline_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package chain

import (
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
)

var _ UnsignedTransaction = &LifelineTx{}
Expand All @@ -28,7 +29,7 @@ func addLife(db database.KeyValueReaderWriter, prefix []byte) error {
return PutPrefixInfo(db, prefix, i, lastExpiry)
}

func (l *LifelineTx) Execute(db database.Database, blockTime uint64) error {
func (l *LifelineTx) Execute(db database.Database, blockTime uint64, _ ids.ID) error {
return addLife(db, l.Prefix)
}

Expand Down
3 changes: 2 additions & 1 deletion chain/lifeline_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/ids"
)

func TestLifelineTx(t *testing.T) {
Expand Down Expand Up @@ -47,7 +48,7 @@ func TestLifelineTx(t *testing.T) {
},
}
for i, tv := range tt {
err := tv.utx.Execute(db, tv.blockTime)
err := tv.utx.Execute(db, tv.blockTime, ids.ID{})
if !errors.Is(err, tv.err) {
t.Fatalf("#%d: tx.Execute err expected %v, got %v", i, tv.err, err)
}
Expand Down
8 changes: 4 additions & 4 deletions chain/set_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type SetTx struct {
Value []byte `serialize:"true" json:"value"`
}

func (s *SetTx) Execute(db database.Database, blockTime uint64) error {
func (s *SetTx) Execute(db database.Database, blockTime uint64, txID ids.ID) error {
// assume prefix is already validated via "BaseTx"
if err := parser.CheckKey(s.Key); err != nil {
return err
Expand Down Expand Up @@ -65,10 +65,10 @@ func (s *SetTx) Execute(db database.Database, blockTime uint64) error {
return fmt.Errorf("%w: expected %x got %x", ErrInvalidKey, id[:], s.Key)
}
}
return s.updatePrefix(db, blockTime, i)
return s.updatePrefix(db, blockTime, txID, i)
}

func (s *SetTx) updatePrefix(db database.Database, blockTime uint64, i *PrefixInfo) error {
func (s *SetTx) updatePrefix(db database.Database, blockTime uint64, txID ids.ID, i *PrefixInfo) error {
v, exists, err := GetValue(db, s.Prefix, s.Key)
if err != nil {
return err
Expand All @@ -88,7 +88,7 @@ func (s *SetTx) updatePrefix(db database.Database, blockTime uint64, i *PrefixIn
i.Units -= valueUnits(v)
}
i.Units += valueUnits(s.Value)
if err := PutPrefixKey(db, s.Prefix, s.Key, s.Value); err != nil {
if err := PutPrefixKey(db, s.Prefix, s.Key, txID[:]); err != nil {
return err
}
}
Expand Down
11 changes: 10 additions & 1 deletion chain/set_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,16 @@ func TestSetTx(t *testing.T) {
t.Fatalf("#%d: ExpireNext errored %v", i, err)
}
}
err := tv.utx.Execute(db, uint64(tv.blockTime))
// Set linked value (normally done in block processing)
id := ids.GenerateTestID()
if tp, ok := tv.utx.(*SetTx); ok {
if len(tp.Value) > 0 {
if err := db.Put(PrefixTxValueKey(id), tp.Value); err != nil {
t.Fatal(err)
}
}
}
err := tv.utx.Execute(db, uint64(tv.blockTime), id)
if !errors.Is(err, tv.err) {
t.Fatalf("#%d: tx.Execute err expected %v, got %v", i, tv.err, err)
}
Expand Down
Loading