Code Monkey home page Code Monkey logo

graviton's People

Contributors

captaindero 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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

graviton's Issues

Use Go modules

This repository seems to use a vendor directory instead of modules, kind of how most people developed Go code 3-4 years ago. Is there a particular reason for that?

I'm happy to help you transition or answer questions. The official docs are at https://golang.org/ref/mod.

Implement graviton.Tree.Size()

Implement a Size() function on the graviton.Tree type in order to let the caller know the number of tree leafs stored.

This would be useful to count the number of stored objects.

Data List in wrong order

Test:
`package main

import (
"fmt"
"strconv"
"time"

"github.com/deroproject/graviton"

)

func main() {

store, _ := graviton.NewDiskStore("db/graviton.db")
//memdb, _ := graviton.NewMemStore() // temporary memory db
ss, _ := store.LoadSnapshot(0)
tree, _ := ss.GetTree("root")

// Create a list of date and store in database
fmt.Println()
today := time.Now()
keys := 1
for x := 0; x < 10; x++ {
	date := today.AddDate(0, 0, x)
	save := fmt.Sprintf("%02d-%02d-%04d", date.Day(), date.Month(), date.Year())
	tree.Put([]byte(strconv.Itoa(keys)), []byte(save))
	keys++
}
graviton.Commit(tree)

fmt.Println()
// Get individual value based on key = "1" example
var key string = "1"
value, _ := tree.Get([]byte(key))
fmt.Printf("SINGLE: key=%s, value=%s\n", key, string(value))
fmt.Println()

// Get first value stored in database
first := tree.Cursor()
k, v, _ := first.First()
fmt.Printf("FIRST: key=%s, value=%s\n", k, v)
fmt.Println()

// Get last value stored in database
last := tree.Cursor()
for k, v, err := last.Last(); err == nil; k, v, err = last.Next() {
	fmt.Printf("LAST key=%s, value=%s\n", k, v)
}
fmt.Println()

// Get last 5 values stored in database
five := tree.Cursor()
count := 5
for k, v, err := five.Last(); err == nil && count != 0; k, v, err = five.Prev() {
	fmt.Printf("LAST%s key=%s, value=%s\n", k, k, v)
	count--
}
fmt.Println()

// Get all values stored in database
c := tree.Cursor()
fmt.Println("ALL:")
for k, v, err := c.First(); err == nil; k, v, err = c.Next() {
	fmt.Printf("key=%s, value=%s\n", k, v)
}

fmt.Println()

}
`

The out put of ALL values + LAST 5 is incorrect
Example:

LAST10 key=10, value=30-01-2023
LAST7 key=7, value=27-01-2023
LAST2 key=2, value=22-01-2023
LAST8 key=8, value=28-01-2023
LAST9 key=9, value=29-01-2023

ALL:
key=1, value=21-01-2023
key=3, value=23-01-2023
key=5, value=25-01-2023
key=6, value=26-01-2023
key=4, value=24-01-2023
key=9, value=29-01-2023
key=8, value=28-01-2023
key=2, value=22-01-2023
key=7, value=27-01-2023
key=10, value=30-01-2023

Please advise how I can correct this as ORDER is very important for me.

slice bounds out of range panic in Unmarshal

panic: runtime error: slice bounds out of range [931:918]

goroutine 4042265 [running]:
github.com/deroproject/graviton.(*Proof).Unmarshal(0xc0195b4fd8, 0xc016f8b000, 0x396, 0x800, 0xc00dca5b80, 0x7fcabd71e838)
        /go/pkg/mod/github.com/deroproject/[email protected]/proof.go:192 +0x785
gitlab.com/vocdoni/go-dvote/statedb/gravitonstate.Verify(0xc014e72380, 0x20, 0x20, 0xc016f8b000, 0x396, 0x800, 0xc00dca5b80, 0x20, 0x40, 0xc0195b50c8, ...)
        /src/statedb/gravitonstate/graviton.go:392 +0x95

I don't have a reproducer program at hand right now, nor an input to Unmarshal to cause the panic, but I think the edge case is fairly easy to reason about.

Since the input bytes determine tracelength and tracebits, we could make those be long, and then abruptly end the input shortly after, causing copy(p.trace[i], buf[done:]) to panic.

I think there should be bounds checks before each buf[done:] slice expression, as otherwise you risk panics. Those inputs should error instead, given that the function already returns an error.

I could provide a patch, but I thought an issue would be better since this fix might need careful thought - particularly with the tests.

Range queries

Stellar project, some real innovation here. Any plans to add range queries?

Unable to print the right order

`package pkg

import (
"fmt"
"strconv"
"time"

"github.com/deroproject/graviton"

)

func RunGraviton() {

store, _ := graviton.NewDiskStore("db/graviton.db")
ss, _ := store.LoadSnapshot(0)
root, _ := ss.GetTree("root")

// Create a list of date and store in database

today := time.Now()
keys := 0
for x := 0; x < 10; x++ {
	date := today.AddDate(0, 0, x)
	save := fmt.Sprintf("%02d-%02d-%04d", date.Day(), date.Month(), date.Year())
	root.Put([]byte(strconv.Itoa(keys)), []byte(save))
	keys++
}
graviton.Commit(root)

// Get first value stored in database
first := root.Cursor()
k, v, _ := first.First()
fmt.Printf("FIRST: key=%s, value=%s\n", k, v)

// Get last value stored in database
last := root.Cursor()
for k, v, err := last.Last(); err == nil; k, v, err = last.Next() {
	fmt.Printf("LAST : key=%s, value=%s\n", k, v)
}

// Get individual value based on key = "2" example
var key string = "2"
value, _ := root.Get([]byte(key))
fmt.Printf("SELECT: key=%s, value=%s\n", key, string(value))

fmt.Println()
fmt.Println("LAST 5:")
// Get last 5 values stored in database
five := root.Cursor()
count := 5
for k, v, err := five.Last(); err == nil && count != 0; k, v, err = five.Prev() {
	fmt.Printf("LAST: key=%s, value=%s\n", k, v)
	count--
}
fmt.Println()

// Get all values stored in database
a := root.Cursor()
fmt.Println("ALL:")
for k, v, err := a.First(); err == nil; k, v, err = a.Next() {
	fmt.Printf("key=%s, value=%s\n", k, v)
}

fmt.Println()

// Count len of db entries..
c := root.Cursor()
lenght := 0

for _, _, err := c.First(); err == nil; _, _, err = c.Next() {
	lenght++
}

fmt.Printf("Len or total records: %d\n", lenght)

}
`

Result:

`$ go run main.go

GRAVITON TEST
FIRST: key=1, value=02-02-2023
LAST : key=7, value=08-02-2023
SELECT: key=2, value=03-02-2023

LAST 5:
LAST: key=7, value=08-02-2023
LAST: key=2, value=03-02-2023
LAST: key=8, value=09-02-2023
LAST: key=9, value=10-02-2023
LAST: key=4, value=05-02-2023

ALL:
key=1, value=02-02-2023
key=0, value=01-02-2023
key=3, value=04-02-2023
key=5, value=06-02-2023
key=6, value=07-02-2023
key=4, value=05-02-2023
key=9, value=10-02-2023
key=8, value=09-02-2023
key=2, value=03-02-2023
key=7, value=08-02-2023

Len or total records: 10
`

Can you help fix this, LAST 5 is incorrect, ALL is not in order, FIRST key also is not the first one.

I really appreciate any help.

Small key

is it possible to get the smallest key in a branch?

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.