Skip to content

Commit

Permalink
Merge pull request ethereum#70 from maticnetwork/develop
Browse files Browse the repository at this point in the history
Merge develop (Apr 20 - May 27) to master
  • Loading branch information
jdkanani authored May 27, 2020
2 parents 710fb49 + 42dc3f0 commit 555e67a
Show file tree
Hide file tree
Showing 53 changed files with 1,250 additions and 583 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/linuxpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Linux package
on:
push:
tags:
- 'v*.*.*'
- "v*.*.*"
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -30,7 +30,7 @@ jobs:
sudo apt-get -yqq install libpq-dev build-essential
gem install --no-document fpm
fpm --version
make bor
cat > bor.service <<- "EOF"
Expand All @@ -39,8 +39,7 @@ jobs:
[Service]
WorkingDirectory=/etc/bor/
EnvironmentFile=/etc/bor/metadata
ExecStartPre=/bin/mkdir -p /var/log/matic-logs/
ExecStart=/bin/bash -c "/usr/bin/bor --datadir /etc/bor/dataDir --port '30303' --rpc --rpcaddr '0.0.0.0' --rpcvhosts '*' --rpccorsdomain '*' --rpcport '8545' --ipcpath /etc/bor/geth.ipc --rpcapi 'bor,db,eth,net,web3,txpool' --networkid ${NETWORK_ID} --gasprice '0' --keystore /etc/bor/dataDir/keystore --unlock ${VALIDATOR_ADDRESS} --password /etc/bor/dataDir/password.txt --allow-insecure-unlock --maxpeers 150 --mine > /var/log/matic-logs/bor.log 2>&1"
ExecStart=/bin/bash -c "/usr/bin/bor --datadir /etc/bor/dataDir --port '30303' --rpc --rpcaddr '0.0.0.0' --rpcvhosts '*' --rpccorsdomain '*' --rpcport '8545' --ipcpath /etc/bor/bor.ipc --rpcapi 'db,eth,net,web3,txpool,bor' --networkid ${NETWORK_ID} --miner.gaslimit '20000000' --txpool.nolocals --txpool.accountslots '128' --txpool.globalslots '20000' --txpool.lifetime '0h16m0s' --keystore /etc/bor/dataDir/keystore --unlock ${VALIDATOR_ADDRESS} --password /etc/bor/dataDir/password.txt --allow-insecure-unlock --maxpeers 150 --mine"
Type=simple
User=root
EOF
Expand All @@ -60,7 +59,7 @@ jobs:
bor.service=/etc/systemd/system/ \
build/bin/bor=/usr/bin/ \
metadata=/etc/bor/
mkdir packages-v${{ env.RELEASE_VERSION }}
mv matic-bor_${{ env.RELEASE_VERSION }}_amd64.deb packages-v${{ env.RELEASE_VERSION }}/
Expand All @@ -75,14 +74,14 @@ jobs:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-east-1' # optional: defaults to us-east-1
SOURCE_DIR: 'packages-v${{ env.RELEASE_VERSION }}'
DEST_DIR: 'v${{ env.RELEASE_VERSION }}'
AWS_REGION: "us-east-1" # optional: defaults to us-east-1
SOURCE_DIR: "packages-v${{ env.RELEASE_VERSION }}"
DEST_DIR: "v${{ env.RELEASE_VERSION }}"

- name: Slack Notification
uses: rtCamp/[email protected]
env:
SLACK_CHANNEL: code-releases
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_TITLE: 'New linux package for Bor v${{ env.RELEASE_VERSION }} just got released'
SLACK_MESSAGE: 'Package has been uploaded to S3 bucket for public use and available at https://matic-public.s3.amazonaws.com/v${{ env.RELEASE_VERSION }}/matic-bor_${{ env.RELEASE_VERSION }}_amd64.deb'
SLACK_TITLE: "New linux package for Bor v${{ env.RELEASE_VERSION }} just got released"
SLACK_MESSAGE: "Package has been uploaded to S3 bucket for public use and available at https://matic-public.s3.amazonaws.com/v${{ env.RELEASE_VERSION }}/matic-bor_${{ env.RELEASE_VERSION }}_amd64.deb"
2 changes: 1 addition & 1 deletion accounts/scwallet/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ import (
"sync"
"time"

pcsc "github.com/gballet/go-libpcsclite"
"github.com/maticnetwork/bor/accounts"
"github.com/maticnetwork/bor/common"
"github.com/maticnetwork/bor/event"
"github.com/maticnetwork/bor/log"
pcsc "github.com/gballet/go-libpcsclite"
)

// Scheme is the URI prefix for smartcard wallets.
Expand Down
2 changes: 1 addition & 1 deletion accounts/scwallet/securechannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"crypto/sha512"
"fmt"

"github.com/maticnetwork/bor/crypto"
pcsc "github.com/gballet/go-libpcsclite"
"github.com/maticnetwork/bor/crypto"
"github.com/wsddn/go-ecdh"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/text/unicode/norm"
Expand Down
2 changes: 1 addition & 1 deletion accounts/scwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import (
"sync"
"time"

pcsc "github.com/gballet/go-libpcsclite"
ethereum "github.com/maticnetwork/bor"
"github.com/maticnetwork/bor/accounts"
"github.com/maticnetwork/bor/common"
"github.com/maticnetwork/bor/core/types"
"github.com/maticnetwork/bor/crypto"
"github.com/maticnetwork/bor/log"
pcsc "github.com/gballet/go-libpcsclite"
"github.com/status-im/keycard-go/derivationpath"
)

Expand Down
2 changes: 1 addition & 1 deletion accounts/usbwallet/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"sync/atomic"
"time"

"github.com/karalabe/usb"
"github.com/maticnetwork/bor/accounts"
"github.com/maticnetwork/bor/event"
"github.com/maticnetwork/bor/log"
"github.com/karalabe/usb"
)

// LedgerScheme is the protocol scheme prefixing account and wallet URLs.
Expand Down
2 changes: 1 addition & 1 deletion accounts/usbwallet/trezor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (
"io"
"math/big"

"github.com/golang/protobuf/proto"
"github.com/maticnetwork/bor/accounts"
"github.com/maticnetwork/bor/accounts/usbwallet/trezor"
"github.com/maticnetwork/bor/common"
"github.com/maticnetwork/bor/common/hexutil"
"github.com/maticnetwork/bor/core/types"
"github.com/maticnetwork/bor/log"
"github.com/golang/protobuf/proto"
)

// ErrTrezorPINNeeded is returned if opening the trezor requires a PIN code. In
Expand Down
2 changes: 1 addition & 1 deletion accounts/usbwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
"sync"
"time"

"github.com/karalabe/usb"
ethereum "github.com/maticnetwork/bor"
"github.com/maticnetwork/bor/accounts"
"github.com/maticnetwork/bor/common"
"github.com/maticnetwork/bor/core/types"
"github.com/maticnetwork/bor/crypto"
"github.com/maticnetwork/bor/log"
"github.com/karalabe/usb"
)

// Maximum time between wallet health checks to detect USB unplugs.
Expand Down
1 change: 1 addition & 0 deletions cmd/bor/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ It expects the genesis file as argument.`,
ArgsUsage: "<filename> (<filename 2> ... <filename N>) <genesisPath>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.HeimdallURLFlag,
utils.CacheFlag,
utils.SyncModeFlag,
utils.GCModeFlag,
Expand Down
2 changes: 1 addition & 1 deletion cmd/bor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func enableWhisper(ctx *cli.Context) bool {

func makeFullNode(ctx *cli.Context) *node.Node {
stack, cfg := makeConfigNode(ctx)
cfg.Eth.HeimdallURL = ctx.String(utils.HeimdallURLFlag.Name)
cfg.Eth.HeimdallURL = ctx.GlobalString(utils.HeimdallURLFlag.Name)
log.Info("Connecting to heimdall service on...", "heimdallURL", cfg.Eth.HeimdallURL)
utils.RegisterEthService(stack, &cfg.Eth)

Expand Down
1 change: 1 addition & 0 deletions cmd/puppeth/wizard_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (w *wizard) makeGenesis() {
Period: 1,
ProducerDelay: 5,
Sprint: 60,
BackupMultiplier: 1,
ValidatorContract: "0x0000000000000000000000000000000000001000",
StateReceiverContract: "0x0000000000000000000000000000000000001001",
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
if config.Clique != nil {
engine = clique.New(config.Clique, chainDb)
} else if config.Bor != nil {
cfg := &eth.Config{Genesis: genesis}
cfg := &eth.Config{Genesis: genesis, HeimdallURL: ctx.GlobalString(HeimdallURLFlag.Name)}
workspace, err := ioutil.TempDir("", "console-tester-")
if err != nil {
Fatalf("failed to create temporary keystore: %v", err)
Expand Down
88 changes: 86 additions & 2 deletions consensus/bor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,33 @@
package bor

import (
"encoding/hex"
"math"
"math/big"
"strconv"
"sync"

lru "github.com/hashicorp/golang-lru"
"github.com/maticnetwork/bor/common"
"github.com/maticnetwork/bor/consensus"
"github.com/maticnetwork/bor/core/types"
"github.com/maticnetwork/bor/crypto"
"github.com/maticnetwork/bor/rpc"
"github.com/xsleonard/go-merkle"
"golang.org/x/crypto/sha3"
)

var (
// MaxCheckpointLength is the maximum number of blocks that can be requested for constructing a checkpoint root hash
MaxCheckpointLength = uint64(math.Pow(2, 15))
)

// API is a user facing RPC API to allow controlling the signer and voting
// mechanisms of the proof-of-authority scheme.
type API struct {
chain consensus.ChainReader
bor *Bor
chain consensus.ChainReader
bor *Bor
rootHashCache *lru.ARCCache
}

// GetSnapshot retrieves the state snapshot at a given block.
Expand Down Expand Up @@ -105,3 +121,71 @@ func (api *API) GetCurrentValidators() ([]*Validator, error) {
}
return snap.ValidatorSet.Validators, nil
}

// GetRootHash returns the merkle root of the start to end block headers
func (api *API) GetRootHash(start uint64, end uint64) (string, error) {
if err := api.initializeRootHashCache(); err != nil {
return "", err
}
key := getRootHashKey(start, end)
if root, known := api.rootHashCache.Get(key); known {
return root.(string), nil
}
length := uint64(end - start + 1)
if length > MaxCheckpointLength {
return "", &MaxCheckpointLengthExceededError{start, end}
}
currentHeaderNumber := api.chain.CurrentHeader().Number.Uint64()
if start > end || end > currentHeaderNumber {
return "", &InvalidStartEndBlockError{start, end, currentHeaderNumber}
}
blockHeaders := make([]*types.Header, end-start+1)
wg := new(sync.WaitGroup)
concurrent := make(chan bool, 20)
for i := start; i <= end; i++ {
wg.Add(1)
concurrent <- true
go func(number uint64) {
blockHeaders[number-start] = api.chain.GetHeaderByNumber(uint64(number))
<-concurrent
wg.Done()
}(i)
}
wg.Wait()
close(concurrent)

headers := make([][32]byte, nextPowerOfTwo(length))
for i := 0; i < len(blockHeaders); i++ {
blockHeader := blockHeaders[i]
header := crypto.Keccak256(appendBytes32(
blockHeader.Number.Bytes(),
new(big.Int).SetUint64(blockHeader.Time).Bytes(),
blockHeader.TxHash.Bytes(),
blockHeader.ReceiptHash.Bytes(),
))

var arr [32]byte
copy(arr[:], header)
headers[i] = arr
}

tree := merkle.NewTreeWithOpts(merkle.TreeOptions{EnableHashSorting: false, DisableHashLeaves: true})
if err := tree.Generate(convert(headers), sha3.NewLegacyKeccak256()); err != nil {
return "", err
}
root := hex.EncodeToString(tree.Root().Hash)
api.rootHashCache.Add(key, root)
return root, nil
}

func (api *API) initializeRootHashCache() error {
var err error
if api.rootHashCache == nil {
api.rootHashCache, err = lru.NewARC(10)
}
return err
}

func getRootHashKey(start uint64, end uint64) string {
return strconv.FormatUint(start, 10) + "-" + strconv.FormatUint(end, 10)
}
Loading

0 comments on commit 555e67a

Please sign in to comment.