Skip to content

change a few configurations special for alpha #434

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 3 commits into from
Nov 19, 2019
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
2 changes: 1 addition & 1 deletion common/constant/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ const (
// MaxMempoolTransactions is maximum transaction in mempool
// For consideration, max mempool tx should equal or greater than MaxNumberOfTransactionsInBlock
// Or just leave it 0 for unlimited mempool transaction
MaxMempoolTransactions = 0
MaxMempoolTransactions = 10000
)
2 changes: 1 addition & 1 deletion common/constant/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ var (
MaxNodeAdmittancePerCycle uint32 = 1
// NodeAdmittanceCycle FIXME: this is for testing only. real value should be 1440, if the mainchain is set to
// smith every minute on average and if we want to accept new nodes once a day
NodeAdmittanceCycle uint32 = 3
NodeAdmittanceCycle uint32 = 180
)
4 changes: 1 addition & 3 deletions common/constant/participationScore.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ const (
// LinkedReceiptScore the score for each receipt that can't proved have relation with previous published receipt via merkle root
UnlinkedReceiptScore float32 = 0.5
// MaxScoreChange the maximum score that node wll get
MaxScoreChange = 10 * int64(ScalarReceiptScore)
MaxScoreChange = 100000000 * 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
// smith too fast
MaxParticipationScore int64 = 10000000000 * int64(ScalarReceiptScore)
Expand Down
2 changes: 1 addition & 1 deletion common/constant/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "time"
const (
ReceiptDatumTypeBlock = uint32(1)
ReceiptDatumTypeTransaction = uint32(2)
ReceiptBatchMaximum = uint32(8) // 256 in production
ReceiptBatchMaximum = uint32(256)
ReceiptNodeMaximum = uint32(8)
ReceiptNumberToPick = 20
ReceiptNumberOfBlockToPick = 1000
Expand Down
1 change: 1 addition & 0 deletions common/constant/smith.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ var (
AverageSmithingBlockHeight = uint32(10)
MaxNumBlocksmithRewards = int(5)
GenerateBlockTimeoutSec = int64(15)
CoinbaseConstant = int64(100) * OneZBC
)
2 changes: 1 addition & 1 deletion common/query/batchReceiptQuery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestBatchReceiptQuery_GetBatchReceipts(t *testing.T) {
}},
want: "SELECT sender_public_key, recipient_public_key, datum_type, datum_hash, " +
"reference_block_height, reference_block_hash, rmr_linked, recipient_signature " +
"FROM batch_receipt ORDER BY reference_block_height ASC LIMIT 8 OFFSET 0",
"FROM batch_receipt ORDER BY reference_block_height ASC LIMIT 256 OFFSET 0",
},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion common/util/ParticipationScore.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func CalculateParticipationScore(linkedReceipt, unlinkedReceipt, maxReceipt uint
unlinkedBlockScore := float32(unlinkedReceipt) * constant.UnlinkedReceiptScore * constant.ScalarReceiptScore
blockScore := int64(linkedBlockScore + unlinkedBlockScore)

scoreChangeOfANode := ((blockScore - halfMaxBlockScore) * constant.MaxScoreChange) / halfMaxBlockScore
scoreChangeOfANode := (blockScore - halfMaxBlockScore) * (constant.MaxScoreChange / halfMaxBlockScore)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my opinion, it's better constant.MaxScoreChange multiply first by blockScore - halfMaxBlockScore before divided to improve the accuracy of score change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's magnitude of few millions, I think it wont cause any problem.
besides, if we multiply first, the golang int64 cant hold the result and screw up the calculations

return scoreChangeOfANode, nil
}

Expand Down
2 changes: 1 addition & 1 deletion core/service/blockCoreService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ func (bs *BlockService) GetBlocksmithAccountAddress(block *model.Block) (string,
}

func (*BlockService) GetCoinbase() int64 {
return 50 * constant.OneZBC
return constant.CoinbaseConstant
}

// todo: move this to blocksmith service
Expand Down
4 changes: 2 additions & 2 deletions core/service/blockCoreService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2707,7 +2707,7 @@ func TestBlockService_GetBlockExtendedInfo(t *testing.T) {
BlocksmithAccountAddress: constant.MainchainGenesisAccountAddress,
TotalReceipts: 1,
ReceiptValue: 50000000,
PopChange: 1000000000,
PopChange: 10000000000000000,
SkippedBlocksmiths: []*model.SkippedBlocksmith{
{
BlocksmithPublicKey: (*mockBlocksmiths)[0].NodePublicKey,
Expand Down Expand Up @@ -2750,7 +2750,7 @@ func TestBlockService_GetBlockExtendedInfo(t *testing.T) {
BlocksmithAccountAddress: bcsAddress1,
TotalReceipts: int64(len(mockPublishedReceipt)),
ReceiptValue: 50000000,
PopChange: 1000000000,
PopChange: 10000000000000000,
SkippedBlocksmiths: []*model.SkippedBlocksmith{
{
BlocksmithPublicKey: (*mockBlocksmiths)[0].NodePublicKey,
Expand Down
61 changes: 40 additions & 21 deletions core/service/mempoolCoreService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ func (*mockMempoolQueryExecutorFail) ExecuteTransaction(qe string, args ...inter
return errors.New("MockedError")
}

func (*mockMempoolQueryExecutorFail) ExecuteSelectRow(qe string, args ...interface{}) *sql.Row {
// While getting last block
db, mock, _ := sqlmock.New()
// "SELECT count() as total_record FROM mempool ORDER BY fee_per_byte DESC"
mockedRows := sqlmock.NewRows([]string{"total_record"})
mockedRows.AddRow(51)
mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(mockedRows)
return db.QueryRow(qe)
}

func buildTransaction(timestamp int64, sender, recipient string) *model.Transaction {
return &model.Transaction{
Version: 1,
Expand Down Expand Up @@ -311,28 +321,37 @@ func (*mockMempoolQueryExecutorSuccess) ExecuteTransaction(qe string, args ...in
func (*mockMempoolQueryExecutorSuccess) ExecuteSelectRow(qe string, args ...interface{}) *sql.Row {
// While getting last block
db, mock, _ := sqlmock.New()
mockedRow := sqlmock.NewRows(query.NewBlockQuery(chaintype.GetChainType(0)).Fields)
mockedRow.AddRow(
mockBlockData.GetID(),
mockBlockData.GetBlockHash(),
mockBlockData.GetPreviousBlockHash(),
mockBlockData.GetHeight(),
mockBlockData.GetTimestamp(),
mockBlockData.GetBlockSeed(),
mockBlockData.GetBlockSignature(),
mockBlockData.GetCumulativeDifficulty(),
mockBlockData.GetSmithScale(),
mockBlockData.GetPayloadLength(),
mockBlockData.GetPayloadHash(),
mockBlockData.GetBlocksmithPublicKey(),
mockBlockData.GetTotalAmount(),
mockBlockData.GetTotalFee(),
mockBlockData.GetTotalCoinBase(),
mockBlockData.GetVersion(),
)
mock.ExpectQuery("").WillReturnRows(mockedRow)
return db.QueryRow("")
switch qe {
case "SELECT count() as total_record FROM mempool ORDER BY fee_per_byte DESC":
mockedRows := sqlmock.NewRows([]string{"total_record"})
mockedRows.AddRow(51)
mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(mockedRows)
return db.QueryRow(qe)
default:
mockedRow := sqlmock.NewRows(query.NewBlockQuery(chaintype.GetChainType(0)).Fields)
mockedRow.AddRow(
mockBlockData.GetID(),
mockBlockData.GetBlockHash(),
mockBlockData.GetPreviousBlockHash(),
mockBlockData.GetHeight(),
mockBlockData.GetTimestamp(),
mockBlockData.GetBlockSeed(),
mockBlockData.GetBlockSignature(),
mockBlockData.GetCumulativeDifficulty(),
mockBlockData.GetSmithScale(),
mockBlockData.GetPayloadLength(),
mockBlockData.GetPayloadHash(),
mockBlockData.GetBlocksmithPublicKey(),
mockBlockData.GetTotalAmount(),
mockBlockData.GetTotalFee(),
mockBlockData.GetTotalCoinBase(),
mockBlockData.GetVersion(),
)
mock.ExpectQuery("").WillReturnRows(mockedRow)
return db.QueryRow("")
}
}

func (*mockMempoolQueryExecutorSuccess) BeginTx() error {
return nil
}
Expand Down