Add some blockchain RPC handlers and DB fetching routines #55

Merged
moodyjon merged 15 commits from blockchain_rpc1 into master 2022-09-14 17:23:35 +02:00
3 changed files with 21 additions and 9 deletions
Showing only changes of commit b298454727 - Show all commits

View file

@ -88,10 +88,10 @@ func min[Ord constraints.Ordered](x, y Ord) Ord {
} }
type BlockGetChunkReq uint32 type BlockGetChunkReq uint32
type blockGetChunkResp string type BlockGetChunkResp string
// 'blockchain.block.get_chunk' // 'blockchain.block.get_chunk'
func (s *BlockchainService) Get_chunk(r *http.Request, req *BlockGetChunkReq, resp **blockGetChunkResp) error { func (s *BlockchainService) Get_chunk(r *http.Request, req *BlockGetChunkReq, resp **BlockGetChunkResp) error {
index := uint32(*req) index := uint32(*req)
db_headers, err := s.DB.GetHeaders(index*CHUNK_SIZE, CHUNK_SIZE) db_headers, err := s.DB.GetHeaders(index*CHUNK_SIZE, CHUNK_SIZE)
if err != nil { if err != nil {
@ -101,7 +101,7 @@ func (s *BlockchainService) Get_chunk(r *http.Request, req *BlockGetChunkReq, re
for _, h := range db_headers { for _, h := range db_headers {
raw = append(raw, h[:]...) raw = append(raw, h[:]...)
} }
headers := blockGetChunkResp(hex.EncodeToString(raw)) headers := BlockGetChunkResp(hex.EncodeToString(raw))
*resp = &headers *resp = &headers
return err return err
} }

View file

@ -27,7 +27,7 @@ func TestGetChunk(t *testing.T) {
jeffreypicard commented 2022-09-09 10:05:19 +02:00 (Migrated from github.com)
Review

Are these tests not running in the ci? This isn't going to work when run in the ci.

Are these tests not running in the ci? This isn't going to work when run in the ci.
jeffreypicard commented 2022-09-11 12:30:05 +02:00 (Migrated from github.com)
Review

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there.

     jsonrpc_blockchain_test.go:18: DB not found
--- SKIP: TestServerGetHeight (0.00s)
=== RUN   TestGetChunk
    jsonrpc_blockchain_test.go:48: DB not found
--- SKIP: TestGetChunk (0.00s)
=== RUN   TestGetHeader
    jsonrpc_blockchain_test.go:83: DB not found
--- SKIP: TestGetHeader (0.00s)
=== RUN   TestGetBalance
    jsonrpc_blockchain_test.go:115: DB not found
--- SKIP: TestGetBalance (0.00s)
=== RUN   TestGetHistory
    jsonrpc_blockchain_test.go:154: DB not found
--- SKIP: TestGetHistory (0.00s)
=== RUN   TestListUnspent
    jsonrpc_blockchain_test.go:193: DB not found
--- SKIP: TestListUnspent (0.00s)

let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there. ``` jsonrpc_blockchain_test.go:18: DB not found --- SKIP: TestServerGetHeight (0.00s) === RUN TestGetChunk jsonrpc_blockchain_test.go:48: DB not found --- SKIP: TestGetChunk (0.00s) === RUN TestGetHeader jsonrpc_blockchain_test.go:83: DB not found --- SKIP: TestGetHeader (0.00s) === RUN TestGetBalance jsonrpc_blockchain_test.go:115: DB not found --- SKIP: TestGetBalance (0.00s) === RUN TestGetHistory jsonrpc_blockchain_test.go:154: DB not found --- SKIP: TestGetHistory (0.00s) === RUN TestListUnspent jsonrpc_blockchain_test.go:193: DB not found --- SKIP: TestListUnspent (0.00s) ``` let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.
moodyjon commented 2022-09-12 23:14:23 +02:00 (Migrated from github.com)
Review

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history".

I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history". I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.
moodyjon commented 2022-09-13 22:08:13 +02:00 (Migrated from github.com)
Review

Added sample data from lbry-sdk integration test. Reworked tests to match.

Added sample data from lbry-sdk integration test. Reworked tests to match.
jeffreypicard commented 2022-09-09 10:05:19 +02:00 (Migrated from github.com)
Review

Are these tests not running in the ci? This isn't going to work when run in the ci.

Are these tests not running in the ci? This isn't going to work when run in the ci.
jeffreypicard commented 2022-09-11 12:30:05 +02:00 (Migrated from github.com)
Review

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there.

     jsonrpc_blockchain_test.go:18: DB not found
--- SKIP: TestServerGetHeight (0.00s)
=== RUN   TestGetChunk
    jsonrpc_blockchain_test.go:48: DB not found
--- SKIP: TestGetChunk (0.00s)
=== RUN   TestGetHeader
    jsonrpc_blockchain_test.go:83: DB not found
--- SKIP: TestGetHeader (0.00s)
=== RUN   TestGetBalance
    jsonrpc_blockchain_test.go:115: DB not found
--- SKIP: TestGetBalance (0.00s)
=== RUN   TestGetHistory
    jsonrpc_blockchain_test.go:154: DB not found
--- SKIP: TestGetHistory (0.00s)
=== RUN   TestListUnspent
    jsonrpc_blockchain_test.go:193: DB not found
--- SKIP: TestListUnspent (0.00s)

let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there. ``` jsonrpc_blockchain_test.go:18: DB not found --- SKIP: TestServerGetHeight (0.00s) === RUN TestGetChunk jsonrpc_blockchain_test.go:48: DB not found --- SKIP: TestGetChunk (0.00s) === RUN TestGetHeader jsonrpc_blockchain_test.go:83: DB not found --- SKIP: TestGetHeader (0.00s) === RUN TestGetBalance jsonrpc_blockchain_test.go:115: DB not found --- SKIP: TestGetBalance (0.00s) === RUN TestGetHistory jsonrpc_blockchain_test.go:154: DB not found --- SKIP: TestGetHistory (0.00s) === RUN TestListUnspent jsonrpc_blockchain_test.go:193: DB not found --- SKIP: TestListUnspent (0.00s) ``` let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.
moodyjon commented 2022-09-12 23:14:23 +02:00 (Migrated from github.com)
Review

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history".

I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history". I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.
moodyjon commented 2022-09-13 22:08:13 +02:00 (Migrated from github.com)
Review

Added sample data from lbry-sdk integration test. Reworked tests to match.

Added sample data from lbry-sdk integration test. Reworked tests to match.
for index := 0; index < 10; index++ { for index := 0; index < 10; index++ {
req := BlockGetChunkReq(index) req := BlockGetChunkReq(index)
var resp *blockGetChunkResp var resp *BlockGetChunkResp
jeffreypicard commented 2022-09-09 10:05:19 +02:00 (Migrated from github.com)
Review

Are these tests not running in the ci? This isn't going to work when run in the ci.

Are these tests not running in the ci? This isn't going to work when run in the ci.
jeffreypicard commented 2022-09-11 12:30:05 +02:00 (Migrated from github.com)
Review

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there.

     jsonrpc_blockchain_test.go:18: DB not found
--- SKIP: TestServerGetHeight (0.00s)
=== RUN   TestGetChunk
    jsonrpc_blockchain_test.go:48: DB not found
--- SKIP: TestGetChunk (0.00s)
=== RUN   TestGetHeader
    jsonrpc_blockchain_test.go:83: DB not found
--- SKIP: TestGetHeader (0.00s)
=== RUN   TestGetBalance
    jsonrpc_blockchain_test.go:115: DB not found
--- SKIP: TestGetBalance (0.00s)
=== RUN   TestGetHistory
    jsonrpc_blockchain_test.go:154: DB not found
--- SKIP: TestGetHistory (0.00s)
=== RUN   TestListUnspent
    jsonrpc_blockchain_test.go:193: DB not found
--- SKIP: TestListUnspent (0.00s)

let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there. ``` jsonrpc_blockchain_test.go:18: DB not found --- SKIP: TestServerGetHeight (0.00s) === RUN TestGetChunk jsonrpc_blockchain_test.go:48: DB not found --- SKIP: TestGetChunk (0.00s) === RUN TestGetHeader jsonrpc_blockchain_test.go:83: DB not found --- SKIP: TestGetHeader (0.00s) === RUN TestGetBalance jsonrpc_blockchain_test.go:115: DB not found --- SKIP: TestGetBalance (0.00s) === RUN TestGetHistory jsonrpc_blockchain_test.go:154: DB not found --- SKIP: TestGetHistory (0.00s) === RUN TestListUnspent jsonrpc_blockchain_test.go:193: DB not found --- SKIP: TestListUnspent (0.00s) ``` let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.
moodyjon commented 2022-09-12 23:14:23 +02:00 (Migrated from github.com)
Review

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history".

I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history". I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.
moodyjon commented 2022-09-13 22:08:13 +02:00 (Migrated from github.com)
Review

Added sample data from lbry-sdk integration test. Reworked tests to match.

Added sample data from lbry-sdk integration test. Reworked tests to match.
jeffreypicard commented 2022-09-09 10:05:19 +02:00 (Migrated from github.com)
Review

Are these tests not running in the ci? This isn't going to work when run in the ci.

Are these tests not running in the ci? This isn't going to work when run in the ci.
jeffreypicard commented 2022-09-11 12:30:05 +02:00 (Migrated from github.com)
Review

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there.

     jsonrpc_blockchain_test.go:18: DB not found
--- SKIP: TestServerGetHeight (0.00s)
=== RUN   TestGetChunk
    jsonrpc_blockchain_test.go:48: DB not found
--- SKIP: TestGetChunk (0.00s)
=== RUN   TestGetHeader
    jsonrpc_blockchain_test.go:83: DB not found
--- SKIP: TestGetHeader (0.00s)
=== RUN   TestGetBalance
    jsonrpc_blockchain_test.go:115: DB not found
--- SKIP: TestGetBalance (0.00s)
=== RUN   TestGetHistory
    jsonrpc_blockchain_test.go:154: DB not found
--- SKIP: TestGetHistory (0.00s)
=== RUN   TestListUnspent
    jsonrpc_blockchain_test.go:193: DB not found
--- SKIP: TestListUnspent (0.00s)

let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there. ``` jsonrpc_blockchain_test.go:18: DB not found --- SKIP: TestServerGetHeight (0.00s) === RUN TestGetChunk jsonrpc_blockchain_test.go:48: DB not found --- SKIP: TestGetChunk (0.00s) === RUN TestGetHeader jsonrpc_blockchain_test.go:83: DB not found --- SKIP: TestGetHeader (0.00s) === RUN TestGetBalance jsonrpc_blockchain_test.go:115: DB not found --- SKIP: TestGetBalance (0.00s) === RUN TestGetHistory jsonrpc_blockchain_test.go:154: DB not found --- SKIP: TestGetHistory (0.00s) === RUN TestListUnspent jsonrpc_blockchain_test.go:193: DB not found --- SKIP: TestListUnspent (0.00s) ``` let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.
moodyjon commented 2022-09-12 23:14:23 +02:00 (Migrated from github.com)
Review

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history".

I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history". I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.
moodyjon commented 2022-09-13 22:08:13 +02:00 (Migrated from github.com)
Review

Added sample data from lbry-sdk integration test. Reworked tests to match.

Added sample data from lbry-sdk integration test. Reworked tests to match.
err := s.Get_chunk(nil, &req, &resp) err := s.Get_chunk(nil, &req, &resp)
if err != nil { if err != nil {
t.Errorf("index: %v handler err: %v", index, err) t.Errorf("index: %v handler err: %v", index, err)

jeffreypicard commented 2022-09-09 10:05:19 +02:00 (Migrated from github.com)
Review

Are these tests not running in the ci? This isn't going to work when run in the ci.

Are these tests not running in the ci? This isn't going to work when run in the ci.
jeffreypicard commented 2022-09-11 12:30:05 +02:00 (Migrated from github.com)
Review

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there.

     jsonrpc_blockchain_test.go:18: DB not found
--- SKIP: TestServerGetHeight (0.00s)
=== RUN   TestGetChunk
    jsonrpc_blockchain_test.go:48: DB not found
--- SKIP: TestGetChunk (0.00s)
=== RUN   TestGetHeader
    jsonrpc_blockchain_test.go:83: DB not found
--- SKIP: TestGetHeader (0.00s)
=== RUN   TestGetBalance
    jsonrpc_blockchain_test.go:115: DB not found
--- SKIP: TestGetBalance (0.00s)
=== RUN   TestGetHistory
    jsonrpc_blockchain_test.go:154: DB not found
--- SKIP: TestGetHistory (0.00s)
=== RUN   TestListUnspent
    jsonrpc_blockchain_test.go:193: DB not found
--- SKIP: TestListUnspent (0.00s)

let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there. ``` jsonrpc_blockchain_test.go:18: DB not found --- SKIP: TestServerGetHeight (0.00s) === RUN TestGetChunk jsonrpc_blockchain_test.go:48: DB not found --- SKIP: TestGetChunk (0.00s) === RUN TestGetHeader jsonrpc_blockchain_test.go:83: DB not found --- SKIP: TestGetHeader (0.00s) === RUN TestGetBalance jsonrpc_blockchain_test.go:115: DB not found --- SKIP: TestGetBalance (0.00s) === RUN TestGetHistory jsonrpc_blockchain_test.go:154: DB not found --- SKIP: TestGetHistory (0.00s) === RUN TestListUnspent jsonrpc_blockchain_test.go:193: DB not found --- SKIP: TestListUnspent (0.00s) ``` let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.
moodyjon commented 2022-09-12 23:14:23 +02:00 (Migrated from github.com)
Review

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history".

I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history". I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.
moodyjon commented 2022-09-13 22:08:13 +02:00 (Migrated from github.com)
Review

Added sample data from lbry-sdk integration test. Reworked tests to match.

Added sample data from lbry-sdk integration test. Reworked tests to match.
jeffreypicard commented 2022-09-09 10:05:19 +02:00 (Migrated from github.com)
Review

Are these tests not running in the ci? This isn't going to work when run in the ci.

Are these tests not running in the ci? This isn't going to work when run in the ci.
jeffreypicard commented 2022-09-11 12:30:05 +02:00 (Migrated from github.com)
Review

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there.

     jsonrpc_blockchain_test.go:18: DB not found
--- SKIP: TestServerGetHeight (0.00s)
=== RUN   TestGetChunk
    jsonrpc_blockchain_test.go:48: DB not found
--- SKIP: TestGetChunk (0.00s)
=== RUN   TestGetHeader
    jsonrpc_blockchain_test.go:83: DB not found
--- SKIP: TestGetHeader (0.00s)
=== RUN   TestGetBalance
    jsonrpc_blockchain_test.go:115: DB not found
--- SKIP: TestGetBalance (0.00s)
=== RUN   TestGetHistory
    jsonrpc_blockchain_test.go:154: DB not found
--- SKIP: TestGetHistory (0.00s)
=== RUN   TestListUnspent
    jsonrpc_blockchain_test.go:193: DB not found
--- SKIP: TestListUnspent (0.00s)

let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there. ``` jsonrpc_blockchain_test.go:18: DB not found --- SKIP: TestServerGetHeight (0.00s) === RUN TestGetChunk jsonrpc_blockchain_test.go:48: DB not found --- SKIP: TestGetChunk (0.00s) === RUN TestGetHeader jsonrpc_blockchain_test.go:83: DB not found --- SKIP: TestGetHeader (0.00s) === RUN TestGetBalance jsonrpc_blockchain_test.go:115: DB not found --- SKIP: TestGetBalance (0.00s) === RUN TestGetHistory jsonrpc_blockchain_test.go:154: DB not found --- SKIP: TestGetHistory (0.00s) === RUN TestListUnspent jsonrpc_blockchain_test.go:193: DB not found --- SKIP: TestListUnspent (0.00s) ``` let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.
moodyjon commented 2022-09-12 23:14:23 +02:00 (Migrated from github.com)
Review

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history".

I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history". I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.
moodyjon commented 2022-09-13 22:08:13 +02:00 (Migrated from github.com)
Review

Added sample data from lbry-sdk integration test. Reworked tests to match.

Added sample data from lbry-sdk integration test. Reworked tests to match.

View file

@ -1,7 +1,6 @@
package server package server
import ( import (
"log"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -9,6 +8,7 @@ import (
"github.com/gorilla/rpc/json" "github.com/gorilla/rpc/json"
"github.com/lbryio/herald.go/db" "github.com/lbryio/herald.go/db"
pb "github.com/lbryio/herald.go/protobuf/go" pb "github.com/lbryio/herald.go/protobuf/go"
log "github.com/sirupsen/logrus"
) )
type ClaimtrieService struct { type ClaimtrieService struct {
@ -41,13 +41,25 @@ func (s *Server) StartJsonRPC() error {
// Register "blockchain.claimtrie.*"" handlers. // Register "blockchain.claimtrie.*"" handlers.
claimtrieSvc := &ClaimtrieService{s.DB} claimtrieSvc := &ClaimtrieService{s.DB}
s1.RegisterService(claimtrieSvc, "blockchain_claimtrie") err := s1.RegisterService(claimtrieSvc, "blockchain_claimtrie")
if err != nil {
log.Errorf("RegisterService: %v\n", err)
}
// Register other "blockchain.{block,address,scripthash}.*" handlers. // Register other "blockchain.{block,address,scripthash}.*" handlers.
blockchainSvc := &BlockchainService{s.DB, s.Chain} blockchainSvc := &BlockchainService{s.DB, s.Chain}
s1.RegisterService(&blockchainSvc, "blockchain_block") err = s1.RegisterService(blockchainSvc, "blockchain_block")
s1.RegisterService(&BlockchainAddressService{*blockchainSvc}, "blockchain_address") if err != nil {
s1.RegisterService(&BlockchainScripthashService{*blockchainSvc}, "blockchain_scripthash") log.Errorf("RegisterService: %v\n", err)
}
err = s1.RegisterService(&BlockchainAddressService{*blockchainSvc}, "blockchain_address")
if err != nil {
log.Errorf("RegisterService: %v\n", err)
}
err = s1.RegisterService(&BlockchainScripthashService{*blockchainSvc}, "blockchain_scripthash")
if err != nil {
log.Errorf("RegisterService: %v\n", err)
}
r := mux.NewRouter() r := mux.NewRouter()
r.Handle("/rpc", s1) r.Handle("/rpc", s1)