Skip to content

Commit e2fbe5b

Browse files
astaphobiaandy-shi88
authored andcommitted
202 node reciepts collection (#265)
* this commit to add batchReceiptQuery * this commit to add batch_receipt and merke_tree migration * this commit to fixed migration bug * this commit to add merkle_tree and batch_receipt query * this commit to add receipt_batch_max const * this commit to add GetSignedReceiptBytes * this commit to modify golangci config * this commit to add interface func batchReceipt Query * this commit to add ReceiptBatchMaximum const * this commit to add merkletree query interface and another func into receiptQuery * this commit to intialize whole new fields PeerServiceClient * this commit rename column receipt_merkle_root to rmr_linked * this commit to add p2p service build * this commit to add model proto * this commit to update query receipt affected * this commit to update that after update proto
1 parent 0473a68 commit e2fbe5b

36 files changed

+1908
-612
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ linters-settings:
3939
goimports:
4040
local-prefixes: github.com/zoobc/zoobc-core
4141
gocritic:
42+
settings:
43+
hugeParam:
44+
sizeThreshold: 512
4245
enabled-tags:
4346
- performance
4447
- style

ZooBC.postman_collection.json

Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,90 @@
11
{
2-
"info": {
3-
"_postman_id": "e8cb55b1-5c13-4894-8106-52f4bf019eee",
4-
"name": "ZooBC",
5-
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
6-
},
7-
"item": [
8-
{
9-
"name": "blocks",
10-
"item": [
11-
{
12-
"name": "GetBlocks",
13-
"request": {
14-
"method": "GET",
15-
"header": [],
16-
"body": {
17-
"mode": "raw",
18-
"raw": ""
19-
},
20-
"url": {
21-
"raw": "{{host}}/v1/block/GetBlocks?Limit=10&Height=0&Chaintype=0",
22-
"host": [
23-
"{{host}}"
24-
],
25-
"path": [
26-
"v1",
27-
"block",
28-
"GetBlocks"
29-
],
30-
"query": [
31-
{
32-
"key": "Limit",
33-
"value": "10"
34-
},
35-
{
36-
"key": "Height",
37-
"value": "0"
38-
},
39-
{
40-
"key": "Chaintype",
41-
"value": "0"
42-
}
43-
]
44-
}
45-
},
46-
"response": []
47-
},
48-
{
49-
"name": "GetBlock",
50-
"request": {
51-
"method": "GET",
52-
"header": [],
53-
"body": {
54-
"mode": "raw",
55-
"raw": ""
56-
},
57-
"url": {
58-
"raw": "{{host}}/v1/block/GetBlock?ID=-8826204794314169398",
59-
"host": [
60-
"{{host}}"
61-
],
62-
"path": [
63-
"v1",
64-
"block",
65-
"GetBlock"
66-
],
67-
"query": [
68-
{
69-
"key": "ID",
70-
"value": "-8826204794314169398"
71-
},
72-
{
73-
"key": "Height",
74-
"value": "20",
75-
"disabled": true
76-
},
77-
{
78-
"key": "Chaintype",
79-
"value": "0",
80-
"disabled": true
81-
}
82-
]
83-
}
84-
},
85-
"response": []
86-
}
87-
]
88-
}
89-
]
2+
"info": {
3+
"_postman_id": "e8cb55b1-5c13-4894-8106-52f4bf019eee",
4+
"name": "ZooBC",
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
6+
},
7+
"item": [
8+
{
9+
"name": "blocks",
10+
"item": [
11+
{
12+
"name": "GetBlocks",
13+
"request": {
14+
"method": "GET",
15+
"header": [],
16+
"body": {
17+
"mode": "raw",
18+
"raw": ""
19+
},
20+
"url": {
21+
"raw": "{{host}}/v1/block/GetBlocks?Limit=10&Height=0&Chaintype=0",
22+
"host": [
23+
"{{host}}"
24+
],
25+
"path": [
26+
"v1",
27+
"block",
28+
"GetBlocks"
29+
],
30+
"query": [
31+
{
32+
"key": "Limit",
33+
"value": "10"
34+
},
35+
{
36+
"key": "Height",
37+
"value": "0"
38+
},
39+
{
40+
"key": "Chaintype",
41+
"value": "0"
42+
}
43+
]
44+
}
45+
},
46+
"response": []
47+
},
48+
{
49+
"name": "GetBlock",
50+
"request": {
51+
"method": "GET",
52+
"header": [],
53+
"body": {
54+
"mode": "raw",
55+
"raw": ""
56+
},
57+
"url": {
58+
"raw": "{{host}}/v1/block/GetBlock?ID=-8826204794314169398",
59+
"host": [
60+
"{{host}}"
61+
],
62+
"path": [
63+
"v1",
64+
"block",
65+
"GetBlock"
66+
],
67+
"query": [
68+
{
69+
"key": "ID",
70+
"value": "-8826204794314169398"
71+
},
72+
{
73+
"key": "Height",
74+
"value": "20",
75+
"disabled": true
76+
},
77+
{
78+
"key": "Chaintype",
79+
"value": "0",
80+
"disabled": true
81+
}
82+
]
83+
}
84+
},
85+
"response": []
86+
}
87+
]
88+
}
89+
]
9090
}

api/handler/nodeHardwareHandler.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package handler
22

33
import (
44
"io"
5-
65
"time"
76

87
"github.com/zoobc/zoobc-core/api/service"

common/constant/participationScore.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package constant
33
const (
44
// ScalarReceiptScore the converter score to avoid calculation in float number
55
ScalarReceiptScore float32 = 1000000
6-
// LinkedReceiptScore the score for each receipt that proved have relation with prevoius published receipt via merkle root
6+
// LinkedReceiptScore the score for each receipt that proved have relation with previous published receipt via merkle root
77
LinkedReceiptScore float32 = 2
8-
// LinkedReceiptScore the score for each receipt that can't proved have relation with prevoius published receipt via merkle root
8+
// LinkedReceiptScore the score for each receipt that can't proved have relation with previous published receipt via merkle root
99
UnlinkedReceiptScore float32 = 0.5
1010
// MaxScoreChange the maximum score that node wll get
1111
MaxScoreChange int64 = 10 * int64(ScalarReceiptScore)

common/constant/receipt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ package constant
33
const (
44
ReceiptDatumTypeBlock = uint32(1)
55
ReceiptDatumTypeTransaction = uint32(2)
6+
ReceiptBatchMaximum = uint32(8) // 256 in production
67
)

common/database/migration.go

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package database
33
import (
44
"fmt"
55

6-
log "github.com/sirupsen/logrus"
76
"github.com/zoobc/zoobc-core/common/query"
87
)
98

@@ -27,11 +26,9 @@ and initialize versions
2726
func (m *Migration) Init() error {
2827

2928
if m.Query != nil {
30-
rows, _ := m.Query.ExecuteSelect("SELECT version FROM migration;", false)
31-
if rows != nil {
32-
defer rows.Close()
33-
var version int
34-
_ = rows.Scan(&version)
29+
var version int
30+
err := m.Query.ExecuteSelectRow("SELECT version FROM migration;").Scan(&version)
31+
if err == nil {
3532
m.CurrentVersion = &version
3633
}
3734

@@ -135,16 +132,36 @@ func (m *Migration) Init() error {
135132
);`,
136133
`
137134
CREATE TABLE IF NOT EXISTS "node_receipt" (
138-
"sender_public_key" BLOB,
135+
"sender_public_key" BLOB,
139136
"recipient_public_key" BLOB,
140137
"datum_type" INTEGER,
141138
"datum_hash" BLOB,
142139
"reference_block_height" INTEGER,
143140
"reference_block_hash" BLOB,
144-
"receipt_merkle_root" BLOB,
141+
"rmr_linked" BLOB,
142+
"recipient_signature" BLOB,
143+
"rmr" BLOB,
144+
"rmr_index" INTEGER
145+
)
146+
`,
147+
`
148+
CREATE TABLE IF NOT EXISTS "batch_receipt" (
149+
"sender_public_key" BLOB,
150+
"recipient_public_key" BLOB,
151+
"datum_type" INTEGER,
152+
"datum_hash" BLOB,
153+
"reference_block_height" INTEGER,
154+
"reference_block_hash" BLOB,
155+
"rmr_linked" BLOB,
145156
"recipient_signature" BLOB
146157
)
147158
`,
159+
`
160+
CREATE TABLE IF NOT EXISTS "merkle_tree" (
161+
"id" BLOB,
162+
"tree" BLOB
163+
)
164+
`,
148165
}
149166
return nil
150167
}
@@ -160,29 +177,25 @@ func (m *Migration) Apply() error {
160177

161178
var (
162179
migrations = m.Versions
180+
err error
163181
)
164182

165183
if m.CurrentVersion != nil {
166-
migrations = m.Versions[*m.CurrentVersion:]
184+
migrations = m.Versions[*m.CurrentVersion+1:]
167185
}
168186

169-
for version, query := range migrations {
170-
var err error
171-
version := version
172-
err = m.Query.BeginTx()
173-
if err != nil {
174-
log.Warn(err)
175-
}
187+
for v, query := range migrations {
188+
version := v
189+
_ = m.Query.BeginTx()
176190
err = m.Query.ExecuteTransaction(query)
177191
if err != nil {
178-
log.Warn(err)
192+
return err
179193
}
180-
181194
if m.CurrentVersion != nil {
182195
err = m.Query.ExecuteTransaction(`UPDATE "migration"
183-
SET "version" = ?, "created_date" = datetime('now');`, *m.CurrentVersion)
196+
SET "version" = ?, "created_date" = datetime('now');`, *m.CurrentVersion+1)
184197
if err != nil {
185-
log.Warn(err)
198+
return err
186199
}
187200
} else {
188201
err = m.Query.ExecuteTransaction(`
@@ -194,13 +207,14 @@ func (m *Migration) Apply() error {
194207
0,
195208
datetime('now')
196209
);
197-
`)
210+
`)
198211
if err != nil {
199-
log.Warn(err)
212+
return err
200213
}
201214
}
202-
err = m.Query.CommitTx()
215+
203216
m.CurrentVersion = &version
217+
err := m.Query.CommitTx()
204218
if err != nil {
205219
return err
206220
}

0 commit comments

Comments
 (0)