Skip to content

395 skipped blocksmith #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8d7e52b
#395 add skipped blocksmith table migration
andy-shi88 Oct 31, 2019
fa6e0bf
#395 initialize skippedBlocksmithQuery
andy-shi88 Oct 31, 2019
18e465d
#395 add skipped blocksmith model
andy-shi88 Oct 31, 2019
1af6986
#395 checkpoint: add skipped blocksmith query
andy-shi88 Oct 31, 2019
9e8cd17
#395 update block height to use uint32
andy-shi88 Oct 31, 2019
3507d3a
#395 add punishment score constant
andy-shi88 Oct 31, 2019
29439da
#395 add rollback for skipped blocksmith
andy-shi88 Oct 31, 2019
2f66923
#395 handle error in buildblocksmith
andy-shi88 Nov 1, 2019
9dea5f8
#395 fix broken rollback in participation score query;
andy-shi88 Nov 1, 2019
f7d9fc5
#395 register participation score query to derived query list
andy-shi88 Nov 1, 2019
79f2ed7
#395 move blocksmith sort to block service
andy-shi88 Nov 1, 2019
49e1f28
#395 remove sort blocksmith listener
andy-shi88 Nov 1, 2019
f931e7e
Merge branch 'develop' of github.com:zoobc/zoobc-core into 395-skippe…
andy-shi88 Nov 1, 2019
26bfa7e
#395 use value instead of pointer
andy-shi88 Nov 1, 2019
0dc9afa
#395 fix query test
andy-shi88 Nov 1, 2019
1f135e7
#395 fix blockchainsync test
andy-shi88 Nov 1, 2019
3790274
#395 fix blockcoreservice test
andy-shi88 Nov 1, 2019
89051ac
#395 fix tests
andy-shi88 Nov 4, 2019
04e9841
#395 add skipped blocksmith to block extended info
andy-shi88 Nov 4, 2019
7abe842
#395 fill real data for block extended info
andy-shi88 Nov 4, 2019
1decc4c
#395 add method for getting receipt score
andy-shi88 Nov 4, 2019
4ba4429
#395 fix test
andy-shi88 Nov 4, 2019
e77b9fc
#395 move tests to block core service
andy-shi88 Nov 4, 2019
3572603
handle error in build model
andy-shi88 Nov 4, 2019
6e9326e
#395 get total node registry at height n when calculating total max r…
andy-shi88 Nov 4, 2019
fc3c1b7
#395 update schema model
andy-shi88 Nov 4, 2019
e5439da
#395 use constant max score change
andy-shi88 Nov 5, 2019
cb66394
#395 merge from develop and fix conflict
andy-shi88 Nov 5, 2019
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
1 change: 1 addition & 0 deletions cmd/block/blockGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func initialize(
query.NewTransactionQuery(chainType),
query.NewMerkleTreeQuery(),
query.NewPublishedReceiptQuery(),
query.NewSkippedBlocksmithQuery(),
crypto.NewSignature(),
mempoolService,
receiptService,
Expand Down
1 change: 1 addition & 0 deletions cmd/genesisblock/genesisGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ func getGenesisBlockID(genesisEntries []genesisEntry) int64 {
nil,
nil,
nil,
nil,
&transaction.TypeSwitcher{},
nil,
nil,
Expand Down
2 changes: 2 additions & 0 deletions common/constant/participationScore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const (
UnlinkedReceiptScore float32 = 0.5
// MaxScoreChange the maximum score that node wll get
MaxScoreChange = 10 * int64(ScalarReceiptScore)
// punishment amount
ParticipationScorePunishAmount = -1 * MaxScoreChange / 2
// MaxReceipt the maximum receipt will publish in every block
MaxReceipt uint32 = 20
// MaxParticipationScore maximum achievable score, this will be important to maintain smithing process so it doesn't
Expand Down
8 changes: 8 additions & 0 deletions common/database/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ func (m *Migration) Init() error {
AlTER TABLE "main_block"
ADD COLUMN "block_hash" BLOB AFTER "id"
`,
`
CREATE TABLE IF NOT EXISTS "skipped_blocksmith" (
"blocksmith_public_key" BLOB,
"pop_change" INTEGER,
"block_height" INTEGER,
"blocksmith_index" INTEGER
)
`,
}
return nil
}
Expand Down
27 changes: 18 additions & 9 deletions common/model/block.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions common/model/skippedBlocksmith.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions common/query/nodeRegistrationQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type (
GetNodeRegistryAtHeight(height uint32) string
ExtractModel(nr *model.NodeRegistration) []interface{}
BuildModel(nodeRegistrations []*model.NodeRegistration, rows *sql.Rows) ([]*model.NodeRegistration, error)
BuildBlocksmith(blocksmiths []*model.Blocksmith, rows *sql.Rows) []*model.Blocksmith
BuildBlocksmith(blocksmiths []*model.Blocksmith, rows *sql.Rows) ([]*model.Blocksmith, error)
BuildNodeAddress(fullNodeAddress string) *model.NodeAddress
ExtractNodeAddress(nodeAddress *model.NodeAddress) string
Scan(nr *model.NodeRegistration, row *sql.Row) error
Expand Down Expand Up @@ -172,7 +172,6 @@ func (nrq *NodeRegistrationQuery) GetNodeRegistryAtHeight(height uint32) string

// ExtractModel extract the model struct fields to the order of NodeRegistrationQuery.Fields
func (nrq *NodeRegistrationQuery) ExtractModel(tx *model.NodeRegistration) []interface{} {

return []interface{}{
tx.NodeID,
tx.NodePublicKey,
Expand All @@ -198,7 +197,10 @@ func (nrq *NodeRegistrationQuery) BuildModel(
dumpString string
)

columns, _ := rows.Columns()
columns, err := rows.Columns()
if err != nil {
return nil, err
}
for i := 0; i < len(columns)-len(nrq.Fields); i++ {
ignoredAggregateColumns = append(ignoredAggregateColumns, &dumpString)
}
Expand All @@ -222,29 +224,36 @@ func (nrq *NodeRegistrationQuery) BuildModel(
&nr.Height,
)
basicFieldsReceiver = append(basicFieldsReceiver, ignoredAggregateColumns...)
_ = rows.Scan(basicFieldsReceiver...)

err := rows.Scan(basicFieldsReceiver...)
if err != nil {
return nil, err
}
nr.NodeAddress = nrq.BuildNodeAddress(fullNodeAddress)
nodeRegistrations = append(nodeRegistrations, &nr)
}
return nodeRegistrations, nil
}

func (*NodeRegistrationQuery) BuildBlocksmith(blocksmiths []*model.Blocksmith, rows *sql.Rows) []*model.Blocksmith {
func (*NodeRegistrationQuery) BuildBlocksmith(
blocksmiths []*model.Blocksmith, rows *sql.Rows,
) ([]*model.Blocksmith, error) {
for rows.Next() {
var (
blocksmith model.Blocksmith
scoreString string
)
_ = rows.Scan(
err := rows.Scan(
&blocksmith.NodeID,
&blocksmith.NodePublicKey,
&scoreString,
)
if err != nil {
return nil, err
}
blocksmith.Score, _ = new(big.Int).SetString(scoreString, 10)
blocksmiths = append(blocksmiths, &blocksmith)
}
return blocksmiths
return blocksmiths, nil
}

// Rollback delete records `WHERE block_height > `height`
Expand Down
10 changes: 5 additions & 5 deletions common/query/participationScoreQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,20 @@ func (ps *ParticipationScoreQuery) Rollback(height uint32) (multiQueries [][]int
return [][]interface{}{
{
fmt.Sprintf("DELETE FROM %s WHERE height > ?", ps.TableName),
[]interface{}{height},
height,
},
{
fmt.Sprintf(`
UPDATE %s SET latest = ?
WHERE height || '_' || id) IN (
SELECT (MAX(height) || '_' || id) as con
WHERE (height || '_' || node_id) IN (
SELECT (MAX(height) || '_' || node_id) as con
FROM %s
GROUP BY id
GROUP BY node_id
)`,
ps.TableName,
ps.TableName,
),
[]interface{}{1},
1,
},
}
}
2 changes: 2 additions & 0 deletions common/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ func GetDerivedQuery(chainType chaintype.ChainType) []DerivedQuery {
NewNodeRegistrationQuery(),
NewAccountBalanceQuery(),
NewAccountDatasetsQuery(),
NewSkippedBlocksmithQuery(),
NewParticipationScoreQuery(),
}
}
2 changes: 2 additions & 0 deletions common/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestGetDerivedQuery(t *testing.T) {
NewNodeRegistrationQuery(),
NewAccountBalanceQuery(),
NewAccountDatasetsQuery(),
NewSkippedBlocksmithQuery(),
NewParticipationScoreQuery(),
},
},
}
Expand Down
Loading