Skip to content

Enhance blocksmith selection #1243

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
404dc0a
first commit
Oct 5, 2020
623aabd
remove comment
Oct 5, 2020
6ad39b8
fix bug
Oct 6, 2020
405bad4
fix error make test
Oct 6, 2020
7661b2b
IsMe ---> isMe
Oct 8, 2020
4bb85e7
add .Unix() at initialisation
Oct 8, 2020
647520b
change func IsBlockValid only return bool
Oct 8, 2020
9310ff5
remove IsBlockTimestampValid
Oct 8, 2020
bae9709
remove WillSmith func from package service
Oct 9, 2020
37a2646
remove func SortBlocksmiths from package strategy
Oct 9, 2020
ad94ba7
remove func IsValidSmithTime from package strategy
Oct 12, 2020
2d62db3
parsing CurrentNodePublicKey
Oct 12, 2020
685987e
update func WillSmith, isMe, IsBlockValid on BlocksmithStrategySpine
Oct 12, 2020
7003e45
create func CumulativeDifficulty on strategy
Oct 13, 2020
fddcf3f
add getRound and temporary-CanPersist function
andy-shi88 Oct 13, 2020
beeac4a
remove func GetSortedBlocksmithsMap from package strategy
Oct 13, 2020
8e1d576
add getSkippedBlocksmith functioon
andy-shi88 Oct 13, 2020
680a1bb
add new func , remove func , change blocksmithIndex to round
Oct 14, 2020
c0fa1ef
Merge branch 'experimental' of github.com:zoobc/zoobc-core into Enhan…
Oct 15, 2020
8e62169
remove parameter 'block' in isMe func
Oct 15, 2020
6692759
fix willsmith
Oct 21, 2020
051b42e
Merge branch 'experimental' of github.com:zoobc/zoobc-core into Enhan…
Oct 21, 2020
8331572
#1190 inject random number generator to strategy main
andy-shi88 Oct 22, 2020
5c872bb
#1190 fix candidate time calculation
andy-shi88 Oct 22, 2020
9e1e773
#1190 separate get smithing round and smithing index function
andy-shi88 Oct 23, 2020
3bd72e7
#1190 temporarily disable spinechain smithing
andy-shi88 Oct 23, 2020
147be92
Implementated the new blocksmith selection on spinechain
Oct 26, 2020
5be7a61
fix bug make test
Oct 27, 2020
bc0e776
delete unit test for now
Oct 27, 2020
4f435ad
remove unused comment
Oct 27, 2020
4fa876d
remove spine strategy
andy-shi88 Nov 2, 2020
fa539c2
#1190 remove unused code
andy-shi88 Nov 2, 2020
39aa861
#1190 fix conflict merging with latest experimental branch
andy-shi88 Nov 2, 2020
bf2ad3a
#1190 fix broken code after conflict
andy-shi88 Nov 2, 2020
8675956
#1190 remove unused field in blocksmith strategy main and blocksmith …
andy-shi88 Nov 3, 2020
93463b6
#1190 clean up code docs
andy-shi88 Nov 3, 2020
cd14257
#1190 enhance: handle large skipped blocksmith db access
andy-shi88 Nov 3, 2020
7e2b2d7
#1190 validate blocksmith public key of first blocksmith
andy-shi88 Nov 3, 2020
c05ced8
#1190 fix conflict
andy-shi88 Nov 3, 2020
cad8dc8
#1190 add function to calculate persist and creation time
andy-shi88 Nov 3, 2020
9bb56fd
#1190 fix unit tests
andy-shi88 Nov 3, 2020
6d5a122
#1190 handle getBlocksBlocksmiths invalid block
andy-shi88 Nov 3, 2020
2638102
#1190 fix conflicts
andy-shi88 Nov 6, 2020
af19d1d
Merge branch 'Enhance-Blocksmith-Selection-1190' of github.com:nawika…
Nov 10, 2020
5535b75
fix bug redeclare
Nov 10, 2020
690d14c
#1190 handle previous block skipped blocksmith - blocktime offset.
andy-shi88 Nov 12, 2020
2576b88
#1190 fix conflicts
andy-shi88 Nov 12, 2020
3afb9e5
#1190 add timestamp field to blocks storage
andy-shi88 Nov 12, 2020
dee6430
#1190 estimate previous block persist time for less smithing time col…
andy-shi88 Nov 12, 2020
f4df41b
#1190 fix unit tests
andy-shi88 Nov 12, 2020
7ec3bb2
#1190 avoid process node-admit, node-expel, blocksmith reward, and sk…
andy-shi88 Nov 13, 2020
e6c2f6e
#1190 use estimated persist timestamp for block validation
andy-shi88 Nov 13, 2020
b65cbdd
Merge branch 'develop' into Enhance-Blocksmith-Selection-1190
andy-shi88 Nov 13, 2020
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
16 changes: 13 additions & 3 deletions cmd/block/blockGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package block

import (
"fmt"
"strings"
"time"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -23,6 +21,8 @@ import (
"github.com/zoobc/zoobc-core/core/smith/strategy"
coreUtil "github.com/zoobc/zoobc-core/core/util"
"github.com/zoobc/zoobc-core/observer"
"strings"
"time"
)

type (
Expand All @@ -37,6 +37,7 @@ var (
blockProcessor smith.BlockchainProcessorInterface
blockService service.BlockServiceInterface
nodeRegistrationService service.NodeRegistrationServiceInterface
blockSmithStrategy strategy.BlocksmithStrategyInterface
blocksmithStrategy strategy.BlocksmithStrategyInterface
queryExecutor query.ExecutorInterface
migration database.Migration
Expand Down Expand Up @@ -192,7 +193,15 @@ func initialize(
)

blocksmithStrategy = strategy.NewBlocksmithStrategyMain(
queryExecutor, query.NewNodeRegistrationQuery(), query.NewSkippedBlocksmithQuery(), activeNodeRegistryCacheStorage, log.New(),
log.New(),
nil,
activeNodeRegistryCacheStorage,
query.NewSkippedBlocksmithQuery(),
query.NewBlockQuery(&chaintype.MainChain{}),
nil,
queryExecutor,
crypto.NewRandomNumberGenerator(),
nil,
)
publishedReceiptUtil := coreUtil.NewPublishedReceiptUtil(
query.NewPublishedReceiptQuery(),
Expand Down Expand Up @@ -254,6 +263,7 @@ func generateBlocks(numberOfBlocks int, blocksmithSecretPhrase, outputPath strin
log.New(),
&mockBlockchainStatusService{},
nodeRegistrationService,
blockSmithStrategy,
)
startTime := time.Now().UnixNano() / 1e6
fmt.Printf("generating %d blocks\n", numberOfBlocks)
Expand Down
4 changes: 0 additions & 4 deletions common/model/blocksmith.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ import (
type Blocksmith struct {
NodeID int64
NodePublicKey []byte
NodeOrder *big.Int
SmithOrder uint32
Score *big.Int
BlockSeed int64
SecretPhrase string
Deadline uint32
}

// NewBlocksmith initiate generator
Expand Down
9 changes: 9 additions & 0 deletions common/query/skippedBlocksmithQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

type (
SkippedBlocksmithQueryInterface interface {
GetNumberOfSkippedBlocksmithsByBlockHeight(blockHeight uint32) (qStr string)
GetSkippedBlocksmithsByBlockHeight(blockHeight uint32) (qStr string)
InsertSkippedBlocksmith(skippedBlocksmith *model.SkippedBlocksmith) (qStr string, args []interface{})
InsertSkippedBlocksmiths(skippedBlockSmiths []*model.SkippedBlocksmith) (str string, args []interface{})
Expand Down Expand Up @@ -54,6 +55,14 @@ func (sbq *SkippedBlocksmithQuery) GetSkippedBlocksmithsByBlockHeight(blockHeigh
)
}

func (sbq *SkippedBlocksmithQuery) GetNumberOfSkippedBlocksmithsByBlockHeight(blockHeight uint32) string {
return fmt.Sprintf(
"SELECT COUNT(*) FROM %s WHERE block_height = %d",
sbq.getTableName(),
blockHeight,
)
}

func (sbq *SkippedBlocksmithQuery) InsertSkippedBlocksmith(
skippedBlocksmith *model.SkippedBlocksmith,
) (qStr string, args []interface{}) {
Expand Down
1 change: 1 addition & 0 deletions common/storage/blocksStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type (
BlockCacheObject struct {
ID int64
Height uint32
Timestamp int64
BlockHash []byte
}
)
Expand Down
1 change: 1 addition & 0 deletions common/util/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func GetBlockByHeightUseBlocksCache(
blockCacheObject.BlockHash = block.BlockHash
blockCacheObject.Height = block.Height
blockCacheObject.ID = block.ID
blockCacheObject.Timestamp = block.GetTimestamp()
return &blockCacheObject, nil
}

Expand Down
64 changes: 0 additions & 64 deletions core/blockchainsync/blockchainOrchestratorService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,67 +335,3 @@ func TestBlockchainOrchestratorService_StartSyncChain(t *testing.T) {
})
}
}

func TestBlockchainOrchestratorService_Start(t *testing.T) {
type fields struct {
SpinechainSyncService BlockchainSyncServiceInterface
MainchainSyncService BlockchainSyncServiceInterface
BlockchainStatusService service.BlockchainStatusServiceInterface
SpineBlockManifestService service.SpineBlockManifestServiceInterface
FileDownloader p2p.FileDownloaderInterface
MainchainSnapshotBlockServices service.SnapshotBlockServiceInterface
Logger *log.Logger
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "error:spineChainSyncError",
fields: fields{
SpinechainSyncService: &MockBlockchainSyncServiceError{},
BlockchainStatusService: &MockBlockchainStatusServiceFinished{},
Logger: log.New(),
},
wantErr: true,
},
{
name: "error:mainChainSyncError",
fields: fields{
SpinechainSyncService: &MockBlockchainSyncServiceSuccess{},
MainchainSyncService: &MockBlockchainSyncServiceError{},
BlockchainStatusService: &MockBlockchainStatusServiceFinished{},
Logger: log.New(),
},
wantErr: true,
},
{
name: "success:allOperationsRunWell",
fields: fields{
SpinechainSyncService: &MockBlockchainSyncServiceSuccess{},
MainchainSyncService: &MockBlockchainSyncServiceSuccess{},
BlockchainStatusService: &MockBlockchainStatusServiceFinished{},
Logger: log.New(),
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bos := &BlockchainOrchestratorService{
SpinechainSyncService: tt.fields.SpinechainSyncService,
MainchainSyncService: tt.fields.MainchainSyncService,
BlockchainStatusService: tt.fields.BlockchainStatusService,
SpineBlockManifestService: tt.fields.SpineBlockManifestService,
FileDownloader: tt.fields.FileDownloader,
MainchainSnapshotBlockServices: tt.fields.MainchainSnapshotBlockServices,
Logger: tt.fields.Logger,
}

if err := bos.Start(); (err != nil) != tt.wantErr {
t.Errorf("BlockchainOrchestratorService.Start() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
4 changes: 0 additions & 4 deletions core/service/blockCoreService.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,5 @@ type (
GetBlocksmithStrategy() strategy.BlocksmithStrategyInterface
ReceivedValidatedBlockTransactionsListener() observer.Listener
BlockTransactionsRequestedListener() observer.Listener
WillSmith(
blocksmith *model.Blocksmith,
blockchainProcessorLastBlockID int64,
) (lastBlockID, blocksmithIndex int64, err error)
}
)
Loading