Skip to content

Commit

Permalink
Merge branch 'dev' into dposr
Browse files Browse the repository at this point in the history
  • Loading branch information
erickyan86 committed Sep 2, 2019
2 parents f4e48fd + e78c161 commit 6393c20
Show file tree
Hide file tree
Showing 31 changed files with 218 additions and 245 deletions.
29 changes: 5 additions & 24 deletions accountmanager/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import (
"github.com/fractalplatform/fractal/types"
)

//export account interface
//IAccount export account interface
type IAccount interface {
//newAccount(accountName common.Name, pubkey common.PubKey) (*Account, error)
GetName() common.Name
//nonce
GetNonce() uint64
Expand All @@ -53,7 +52,7 @@ type IAccount interface {
SetDestroy()
}

//export account manager interface
//IAccountManager export account manager interface
type IAccountManager interface {
//account
AccountIsExist(accountName common.Name) (bool, error)
Expand All @@ -74,29 +73,11 @@ type IAccountManager interface {
IncAsset2Acct(fromName common.Name, toName common.Name, assetId uint64, amount *big.Int) error
AddBalanceByName(accountName common.Name, assetID uint64, amount *big.Int) error
Process(action *types.Action) error
//to EVM
//GetCode(accountName common.Name) ([]byte, error)
//SetCode(accountName common.Name, code []byte) (bool, error)
//GetCodeHash(accountName common.Name) (common.Hash, error)
//GetCodeSize(accountName common.Name) (uint64, error)
}

// import
type SdbIf interface {
//IStateDB export state database interface
type IStateDB interface {
Put(account string, key string, value []byte)
Get(account string, key string) ([]byte, error)
// GetSnapshot(accountName string, key string, time uint64) ([]byte, error)
// GetSnapshotLast() (uint64, error)
// GetSnapshotPrev(time uint64) (uint64, error)
// Snapshot() int
RevertToSnapshot(revid int)
RevertToSnapshot(revisionID int)
}

//import
//type AccountAssetIf interface {
// GetAssetIDByName(assetName string) (uint64, error)
// IssueAssetObject(ao *AssetObject) error
// IssueAsset(assetName string, symbol string, amount *big.Int, owner string) error
// IncreaseAsset(accountName string, assetId uint64, amount *big.Int) error
// SetAssetNewOwner(accountName string, assetId uint64, newOwner string) error
//}
12 changes: 6 additions & 6 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type BlockChain struct {
fcontroller *ForkController // fcontroller
processor processor.Processor // block processor interface
validator processor.Validator // block and state validator interface
station *BlockchainStation // p2p station
station *Station // p2p station

headerCache *lru.Cache // Cache for the most recent block headers
tdCache *lru.Cache // Cache for the most recent block total difficulties
Expand Down Expand Up @@ -178,7 +178,7 @@ func NewBlockChain(db fdb.Database, statePruning bool, vmConfig vm.Config, chain
log.Info("Start chain with a specified block number", "start", bc.CurrentBlock().NumberU64(), "irreversible", bc.IrreversibleNumber())
}

bc.station = newBlockchainStation(bc, 0)
bc.station = newStation(bc, 0)
go bc.update()
return bc, nil
}
Expand Down Expand Up @@ -668,11 +668,11 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.

rawdb.WriteReceipts(batch, block.Hash(), block.NumberU64(), receipts)
if bc.vmConfig.ContractLogFlag {
detailtxs := make([]*types.DetailTx, len(receipts))
detailTxs := make([]*types.DetailTx, len(receipts))
for i := 0; i < len(receipts); i++ {
detailtxs[i] = receipts[i].GetInternalTxsLog()
detailTxs[i] = receipts[i].GetInternalTxsLog()
}
rawdb.WriteDetailTxs(batch, block.Hash(), block.NumberU64(), detailtxs)
rawdb.WriteDetailTxs(batch, block.Hash(), block.NumberU64(), detailTxs)
}

currentBlock := bc.CurrentBlock()
Expand Down Expand Up @@ -713,7 +713,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
return isCanon, err
}

// StatePruning enale/disable state pruning
// StatePruning enable/disable state pruning
func (bc *BlockChain) StatePruning(enable bool) (bool, uint64) {
bc.chainmu.Lock()
defer bc.chainmu.Unlock()
Expand Down
38 changes: 19 additions & 19 deletions blockchain/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ const (
maxKnownBlocks = 1024 // Maximum block hashes to keep in the known list (prevent DOS)
)

type errid int
type errorID int

const (
other errid = iota
other errorID = iota
ioTimeout
ioClose
notFind
Expand All @@ -56,7 +56,7 @@ const (
// Error represent error by downloader
type Error struct {
error
eid errid
eid errorID
}

type stationStatus struct {
Expand Down Expand Up @@ -288,7 +288,7 @@ func syncReq(e *router.Event, recvCode int, recvType interface{}, timeout time.D
return waitEvent(errch, ch, timeout)
}

func getBlockHashes(from router.Station, to router.Station, req *getBlcokHashByNumber, errch chan struct{}) ([]common.Hash, *Error) {
func getBlockHashes(from router.Station, to router.Station, req *getBlockHashByNumber, errch chan struct{}) ([]common.Hash, *Error) {
se := &router.Event{
From: from,
To: to,
Expand Down Expand Up @@ -349,16 +349,16 @@ func (dl *Downloader) findAncestor(from router.Station, to router.Station, headN
if headNumber < 1 {
return 0, nil
}
find := func(headnu, length uint64) (uint64, *Error) {
hashes, err := getBlockHashes(from, to, &getBlcokHashByNumber{headNumber, length, 0, true}, errCh)
find := func(headNum, length uint64) (uint64, *Error) {
hashes, err := getBlockHashes(from, to, &getBlockHashByNumber{headNumber, length, 0, true}, errCh)
if err != nil {
return 0, err
}

for i, hash := range hashes {
if dl.blockchain.HasBlock(hash, headnu-uint64(i)) {
log.Debug("downloader findAncestor", "hash", hash.Hex(), "number", headnu-uint64(i))
return headnu - uint64(i), nil
if dl.blockchain.HasBlock(hash, headNum-uint64(i)) {
log.Debug("downloader findAncestor", "hash", hash.Hex(), "number", headNum-uint64(i))
return headNum - uint64(i), nil
}
}
return 0, &Error{errors.New("not find"), notFind}
Expand Down Expand Up @@ -456,14 +456,14 @@ func (dl *Downloader) multiplexDownload(status *stationStatus) bool {

ancestor, err := dl.findAncestor(stationSearch, status.station, headNumber, status.ancestor, status.errCh)
if err != nil {
log.Warn("ancestor err", "err", err, "errid:", err.eid)
log.Warn("ancestor err", "err", err, "errID:", err.eid)
if err.eid == notFind {
log.Warn("Disconnect because ancestor not find:", "node:", adaptor.GetFnode(status.station))
router.SendTo(nil, nil, router.OneMinuteLimited, status.station) // disconnect and put into blacklist
}
return false
}
log.Debug("downloader ancestro:", "ancestor", ancestor)
log.Debug("downloader ancestor:", "ancestor", ancestor)
downloadStart := ancestor
downloadAmount := statusNumber - ancestor
if downloadAmount == 0 { // maybe the status of remote was changed
Expand All @@ -484,7 +484,7 @@ func (dl *Downloader) multiplexDownload(status *stationStatus) bool {
hashes = append(hashes, dl.blockchain.GetHeaderByNumber(numbers[0]).Hash())

if len(numbers[1:]) > 0 {
hash, err := getBlockHashes(stationSearch, status.station, &getBlcokHashByNumber{
hash, err := getBlockHashes(stationSearch, status.station, &getBlockHashByNumber{
Number: numbers[1],
Amount: uint64(len(numbers[1:])),
Skip: downloadSkip,
Expand All @@ -498,7 +498,7 @@ func (dl *Downloader) multiplexDownload(status *stationStatus) bool {

if numbers[len(numbers)-1] != downloadEnd {
numbers = append(numbers, downloadEnd)
hash, err := getBlockHashes(stationSearch, status.station, &getBlcokHashByNumber{
hash, err := getBlockHashes(stationSearch, status.station, &getBlockHashByNumber{
Number: downloadEnd,
Amount: 1,
Skip: 0,
Expand Down Expand Up @@ -572,7 +572,7 @@ func (dl *Downloader) assignDownloadTask(hashes []common.Hash, numbers []uint64)
dl.remotesMutex.RLock()
workers.data = append(workers.data, dl.remotes.data...)
dl.remotesMutex.RUnlock()
taskes := &simpleHeap{
tasks := &simpleHeap{
data: make([]interface{}, 0, len(numbers)-1),
cmp: func(a, b interface{}) int {
wa, wb := a.(*downloadTask), b.(*downloadTask)
Expand All @@ -581,7 +581,7 @@ func (dl *Downloader) assignDownloadTask(hashes []common.Hash, numbers []uint64)
}
resultCh := make(chan *downloadTask)
for i := len(numbers) - 1; i > 0; i-- {
taskes.push(&downloadTask{
tasks.push(&downloadTask{
startNumber: numbers[i-1],
startHash: hashes[i-1],
endNumber: numbers[i],
Expand All @@ -594,7 +594,7 @@ func (dl *Downloader) assignDownloadTask(hashes []common.Hash, numbers []uint64)
if worker == nil {
return nil
}
task := taskes.pop()
task := tasks.pop()
if task == nil {
workers.push(worker)
return nil
Expand Down Expand Up @@ -622,10 +622,10 @@ func (dl *Downloader) assignDownloadTask(hashes []common.Hash, numbers []uint64)
taskCount--
if len(task.blocks) == 0 {
if task.errorTotal > 5 {
taskes.clear()
tasks.clear()
continue
}
taskes.push(task)
tasks.push(task)
} else {
workers.push(task.worker)
insertList[task.startNumber] = task.blocks
Expand Down Expand Up @@ -682,7 +682,7 @@ func (task *downloadTask) Do() {
router.StationRegister(station)
defer router.StationUnregister(station)

reqHash := &getBlcokHashByNumber{task.startNumber, 2, task.endNumber - task.startNumber - 1, false}
reqHash := &getBlockHashByNumber{task.startNumber, 2, task.endNumber - task.startNumber - 1, false}
if task.endNumber == task.startNumber {
reqHash.Skip = 0
reqHash.Amount = 1
Expand Down

0 comments on commit 6393c20

Please sign in to comment.