Skip to content

Commit

Permalink
Merge pull request #35 from raventrov/master
Browse files Browse the repository at this point in the history
Support ofr privacy contract on windows
  • Loading branch information
benbaley authored Feb 28, 2019
2 parents 3083ee6 + e6cd477 commit a9a9514
Show file tree
Hide file tree
Showing 49 changed files with 2,012 additions and 577 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ platon-with-mpc:

platon-with-vc:
build/build_deps.sh
build/build_snark.sh
build/env.sh go run build/ci.go install -vc on ./cmd/platon
@echo "Done building platon with vc."
@echo "Run \"$(GOBIN)/platon\" to launch platon."

platon-with-mv:
build/build_deps.sh
build/build_snark.sh
build/env.sh go run build/ci.go install -mv on ./cmd/platon
@echo "Done building platon with vc."
@echo "Run \"$(GOBIN)/platon\" to launch platon."

swarm:
build/env.sh go run build/ci.go install ./cmd/swarm
@echo "Done building."
Expand All @@ -48,8 +56,14 @@ all-with-mpc:

all-with-vc:
build/build_deps.sh
build/build_snark.sh
build/env.sh go run build/ci.go install -vc on

all-with-mv:
build/build_deps.sh
build/build_snark.sh
build/env.sh go run build/ci.go install -mv on

android:
build/env.sh go run build/ci.go aar --local
@echo "Done building."
Expand Down
18 changes: 14 additions & 4 deletions build/build_snark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ Get_Dist_Name()
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
DISTRO='Debian'
PM='apt'
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
DISTRO='Ubuntu'
elif grep -Eqi "Ubuntu 18.04" /etc/issue || grep -Eq "Ubuntu 18.04" /etc/*-release; then
DISTRO='Ubuntu18'
PM='apt'
elif grep -Eqi "Ubuntu 16.04" /etc/issue || grep -Eq "Ubuntu 16.04" /etc/*-release; then
DISTRO='Ubuntu16'
PM='apt'
elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then
DISTRO='Raspbian'
Expand Down Expand Up @@ -59,11 +62,18 @@ fi
SF_BUILD=$root/vc/build
MAKE="make"
if [ `expr substr $(uname -s) 1 5` = "Linux" ]; then
if [ "$DISTRO" = "Ubuntu" ]; then
if [ "$DISTRO" = "Ubuntu16" ]; then
echo "Ubuntu 16.04 install lib"
sudo apt-get install llvm-6.0-dev llvm-6.0 libclang-6.0-dev
sudo apt-get install libgmpxx4ldbl libgmp-dev libprocps4-dev
sudo apt-get install libboost-all-dev libssl-dev
elif [ "$DISTRO" = "Ubuntu18" ]; then
echo "Ubuntu 18.04 install lib"
sudo apt-get install llvm-6.0-dev llvm-6.0 libclang-6.0-dev
sudo apt-get install libgmpxx4ldbl libgmp-dev libprocps-dev
sudo apt-get install libboost-all-dev libssl-dev
elif [ "$DISTRO" = "CentOS" ]; then
sudo yum install -y llvm clang gmp procps
sudo yum install -y llvm clang gmp procps
else
echo "not support system $DISTRO"
fi
Expand Down
16 changes: 10 additions & 6 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,12 @@ func main() {
func doInstall(cmdline []string) {
// ./cmd/platon
var (
arch = flag.String("arch", "", "Architecture to cross build for")
cc = flag.String("cc", "", "C compiler to cross build with")
mpc = flag.String("mpc", "off", "Switch of mpc , on for compiling MPC, off for without compiling")
vc = flag.String("vc", "off", "Switch of vc , on for compiling VC, off for without compiling")
arch = flag.String("arch", "", "Architecture to cross build for")
cc = flag.String("cc", "", "C compiler to cross build with")
mpc = flag.String("mpc", "off", "Switch of mpc , on for compiling MPC, off for without compiling")
gcflags = flag.String("gcflags", "", "Turn off compiler code optimization and function inlining")
vc = flag.String("vc", "off", "Switch of vc , on for compiling VC, off for without compiling")
mv = flag.String("mv", "off", "Switch of mv , on for compilingMPC and VC, off for without compiling")
)
flag.CommandLine.Parse(cmdline)
env := build.Env()
Expand Down Expand Up @@ -250,11 +251,14 @@ func doInstall(cmdline []string) {
if *mpc == "on" {
goinstall.Args = append(goinstall.Args, "-tags=mpcon")
}
if *gcflags == "on" {
goinstall.Args = append(goinstall.Args, "-gcflags=-N -l")
}
if *vc == "on" {
goinstall.Args = append(goinstall.Args, "-tags=vcon")
}
if *gcflags == "on" {
goinstall.Args = append(goinstall.Args, "-gcflags=-N -l")
if *mv == "on" {
goinstall.Args = append(goinstall.Args, "-tags=mpcon vcon")
}
goinstall.Args = append(goinstall.Args, packages...)
build.MustRun(goinstall)
Expand Down
9 changes: 4 additions & 5 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ var (
Value: "",
}
MPCActorFlag = cli.StringFlag{
Name: "mpc.actor",
Name: "mpc.actor",
Usage: "The address of actor to exec mpc compute",
Value: "",
}
Expand Down Expand Up @@ -889,7 +889,6 @@ func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
}
}


// MakePasswordList reads password lines from the file specified by the global --password flag.
func MakePasswordList(ctx *cli.Context) []string {
path := ctx.GlobalString(PasswordFileFlag.Name)
Expand Down Expand Up @@ -1244,12 +1243,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
switch {
case ctx.GlobalBool(TestnetFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 3
cfg.NetworkId = 103
}
cfg.Genesis = core.DefaultTestnetGenesisBlock()
case ctx.GlobalBool(RinkebyFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 4
cfg.NetworkId = 104
}
cfg.Genesis = core.DefaultRinkebyGenesisBlock()
case ctx.GlobalBool(DeveloperFlag.Name):
Expand Down Expand Up @@ -1413,7 +1412,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
}
cache := &core.CacheConfig{
Disabled: /*ctx.GlobalString(GCModeFlag.Name) == "archive"*/ true,
Disabled:/*ctx.GlobalString(GCModeFlag.Name) == "archive"*/ true,
TrieNodeLimit: eth.DefaultConfig.TrieCache,
TrieTimeLimit: eth.DefaultConfig.TrieTimeout,
}
Expand Down
36 changes: 20 additions & 16 deletions consensus/cbft/cbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,12 @@ func (lower *BlockExt) isAncestor(higher *BlockExt) bool {
return false
}

// findHighest finds the highest block from current start; If there are multiple highest blockExts, return the one that has most signs
// findHighest finds the highest block from current start; If there are multiple highest blockExts, returns the one that singed by self; if none of blocks signed by self, returns the one that has most signs
func (cbft *Cbft) findHighest(current *BlockExt) *BlockExt {
highest := current
for _, child := range current.children {
current := cbft.findHighest(child)
if current.block.NumberU64() > highest.block.NumberU64() || (current.block.NumberU64() == highest.block.NumberU64() && len(current.signs) > len(highest.signs)) {
if current.block.NumberU64() > highest.block.NumberU64() || (current.block.NumberU64() == highest.block.NumberU64() && (current.isSigned || len(current.signs) > len(highest.signs))) {
highest = current
}
}
Expand Down Expand Up @@ -525,6 +525,7 @@ func (cbft *Cbft) execute(ext *BlockExt, parent *BlockExt) error {
sealHash := ext.block.Header().SealHash()
cbft.blockChainCache.WriteReceipts(sealHash, receipts, ext.block.NumberU64())
cbft.blockChainCache.WriteStateDB(sealHash, state, ext.block.NumberU64())
//cbft.blockChainCache.MarkBlockHash(ext.block.Hash())
} else {
cbft.log.Error("execute block error", "hash", ext.block.Hash(), "number", ext.block.NumberU64(), "ParentHash", parent.block.Hash(), "err", err)
return errors.New("execute block error")
Expand Down Expand Up @@ -601,7 +602,7 @@ func (cbft *Cbft) setHighestLogical(highestLogical *BlockExt) {
func SetBackend(blockChain *core.BlockChain, txPool *core.TxPool) {
cbft.log.Debug("call SetBackend()")
cbft.blockChain = blockChain
cbft.ppos.SetStartTimeOfEpoch(blockChain.Genesis().Time().Int64())
cbft.ppos.SetStartTimeOfEpoch(blockChain.Genesis().Time().Int64() / 1000)

currentBlock := blockChain.CurrentBlock()

Expand Down Expand Up @@ -1252,8 +1253,6 @@ func (cbft *Cbft) cleanByNumber(upperLimit uint64) {
}
}



// Author implements consensus.Engine, returning the Ethereum address recovered
// from the signature in the header's extra-data section.
func (cbft *Cbft) Author(header *types.Header) (common.Address, error) {
Expand Down Expand Up @@ -1702,6 +1701,8 @@ func (cbft *Cbft) calTurn(timePoint int64, parentNumber *big.Int, parentHash com
if consensusNodes == nil || len(consensusNodes) <= 0 {
log.Error("calTurn consensusNodes is emtpy~")
return false
} else if len(consensusNodes) == 1 {
return true
}

durationPerTurn := durationPerNode * int64(len(consensusNodes))
Expand Down Expand Up @@ -1792,12 +1793,12 @@ func toMilliseconds(t time.Time) int64 {

func (cbft *Cbft) ShouldSeal(parentNumber *big.Int, parentHash common.Hash, commitNumber *big.Int) bool {
cbft.log.Trace("call ShouldSeal()")
consensusNodes := cbft.ConsensusNodes(parentNumber, parentHash, commitNumber)
if consensusNodes != nil && len(consensusNodes) == 1 {
return true
}

//consensusNodes := cbft.ConsensusNodes(parentNumber, parentHash, commitNumber)
//if consensusNodes != nil && len(consensusNodes) == 1 {
// return true
//}

inturn := cbft.inTurn(parentNumber, parentHash, commitNumber)
if inturn {
cbft.netLatencyLock.RLock()
Expand All @@ -1812,7 +1813,6 @@ func (cbft *Cbft) ShouldSeal(parentNumber *big.Int, parentHash common.Hash, comm
return inturn
}


func (cbft *Cbft) CurrentNodes(parentNumber *big.Int, parentHash common.Hash, blockNumber *big.Int) []*discover.Node {
return cbft.ppos.getCurrentNodes(parentNumber, parentHash, blockNumber)
}
Expand Down Expand Up @@ -1885,20 +1885,24 @@ func (cbft *Cbft) accumulateRewards(config *params.ChainConfig, state *state.Sta
}
var nodeId discover.NodeID
var err error
log.Info("Call accumulateRewards block header", " extra: ", hexutil.Encode(header.Extra))
if ok := bytes.Equal(header.Extra[32:96], make([]byte, 64)); ok {
log.Warn("Call accumulateRewards block header extra[32:96] is empty!")
nodeId = cbft.config.NodeID
} else {
if nodeId, _, err = ecrecover(header); err!=nil {
if nodeId, _, err = ecrecover(header); err != nil {
log.Error("Failed to Call accumulateRewards, ecrecover faile", " err: ", err)
return
} else {
log.Info("Success ecrecover", " nodeid: ", nodeId.String())
}
}

log.Info("Call accumulateRewards", "nodeid: ", nodeId.String())
var can *types.Candidate
if big.NewInt(0).Cmp(new(big.Int).Rem(header.Number, big.NewInt(BaseSwitchWitness))) == 0 {
can, err = cbft.ppos.GetWitnessCandidate(state, nodeId, -1)
}else {
} else {
can, err = cbft.ppos.GetWitnessCandidate(state, nodeId, 0)
}
if err != nil {
Expand All @@ -1910,7 +1914,7 @@ func (cbft *Cbft) accumulateRewards(config *params.ChainConfig, state *state.Sta
return
}
log.Info("Call accumulateRewards, GetTicket ", "TicketId: ", can.TicketId.Hex())
ticket, err := cbft.ppos.ticketPool.GetTicket(state, can.TicketId)
ticket, err := cbft.ppos.GetTicket(state, can.TicketId)
if nil != err {
log.Error("Failed to Call accumulateRewards, GetTicket faile ", " err: ", err.Error())
return
Expand Down Expand Up @@ -1965,4 +1969,4 @@ func GetAmount(number *big.Int) *big.Int {

func (cbft *Cbft) ForEachStorage(state *state.StateDB, title string) {
cbft.ppos.ForEachStorage(state, title)
}
}
Loading

0 comments on commit a9a9514

Please sign in to comment.