good morning!!!!

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • github/maticnetwork/bor
  • open/bor
2 results
Show changes
Showing
with 261 additions and 49 deletions
...@@ -40,7 +40,8 @@ import ( ...@@ -40,7 +40,8 @@ import (
) )
var ( var (
deadline = 5 * time.Minute deadline = 5 * time.Minute
borLogs bool = true
) )
type testBackend struct { type testBackend struct {
...@@ -174,7 +175,7 @@ func TestBlockSubscription(t *testing.T) { ...@@ -174,7 +175,7 @@ func TestBlockSubscription(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewPublicFilterAPI(backend, false, deadline, borLogs)
genesis = (&core.Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db) genesis = (&core.Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db)
chain, _ = core.GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 10, func(i int, gen *core.BlockGen) {}) chain, _ = core.GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 10, func(i int, gen *core.BlockGen) {})
chainEvents = []core.ChainEvent{} chainEvents = []core.ChainEvent{}
...@@ -226,7 +227,7 @@ func TestPendingTxFilter(t *testing.T) { ...@@ -226,7 +227,7 @@ func TestPendingTxFilter(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewPublicFilterAPI(backend, false, deadline, borLogs)
transactions = []*types.Transaction{ transactions = []*types.Transaction{
types.NewTransaction(0, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil), types.NewTransaction(0, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil),
...@@ -281,7 +282,7 @@ func TestLogFilterCreation(t *testing.T) { ...@@ -281,7 +282,7 @@ func TestLogFilterCreation(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewPublicFilterAPI(backend, false, deadline, borLogs)
testCases = []struct { testCases = []struct {
crit FilterCriteria crit FilterCriteria
...@@ -325,7 +326,7 @@ func TestInvalidLogFilterCreation(t *testing.T) { ...@@ -325,7 +326,7 @@ func TestInvalidLogFilterCreation(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewPublicFilterAPI(backend, false, deadline, borLogs)
) )
// different situations where log filter creation should fail. // different situations where log filter creation should fail.
...@@ -347,7 +348,7 @@ func TestInvalidGetLogsRequest(t *testing.T) { ...@@ -347,7 +348,7 @@ func TestInvalidGetLogsRequest(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewPublicFilterAPI(backend, false, deadline, borLogs)
blockHash = common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111") blockHash = common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111")
) )
...@@ -372,7 +373,7 @@ func TestLogFilter(t *testing.T) { ...@@ -372,7 +373,7 @@ func TestLogFilter(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewPublicFilterAPI(backend, false, deadline, borLogs)
firstAddr = common.HexToAddress("0x1111111111111111111111111111111111111111") firstAddr = common.HexToAddress("0x1111111111111111111111111111111111111111")
secondAddr = common.HexToAddress("0x2222222222222222222222222222222222222222") secondAddr = common.HexToAddress("0x2222222222222222222222222222222222222222")
...@@ -486,7 +487,7 @@ func TestPendingLogsSubscription(t *testing.T) { ...@@ -486,7 +487,7 @@ func TestPendingLogsSubscription(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewPublicFilterAPI(backend, false, deadline, borLogs)
firstAddr = common.HexToAddress("0x1111111111111111111111111111111111111111") firstAddr = common.HexToAddress("0x1111111111111111111111111111111111111111")
secondAddr = common.HexToAddress("0x2222222222222222222222222222222222222222") secondAddr = common.HexToAddress("0x2222222222222222222222222222222222222222")
...@@ -670,7 +671,7 @@ func TestPendingTxFilterDeadlock(t *testing.T) { ...@@ -670,7 +671,7 @@ func TestPendingTxFilterDeadlock(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, timeout) api = NewPublicFilterAPI(backend, false, timeout, borLogs)
done = make(chan struct{}) done = make(chan struct{})
) )
......
...@@ -35,7 +35,7 @@ import ( ...@@ -35,7 +35,7 @@ import (
const sampleNumber = 3 // Number of transactions sampled in a block const sampleNumber = 3 // Number of transactions sampled in a block
var ( var (
DefaultMaxPrice = big.NewInt(500 * params.GWei) DefaultMaxPrice = big.NewInt(5000 * params.GWei)
DefaultIgnorePrice = big.NewInt(2 * params.Wei) DefaultIgnorePrice = big.NewInt(2 * params.Wei)
) )
......
...@@ -234,6 +234,8 @@ func generateTestChain() (*core.Genesis, []*types.Block) { ...@@ -234,6 +234,8 @@ func generateTestChain() (*core.Genesis, []*types.Block) {
} }
func TestEthClient(t *testing.T) { func TestEthClient(t *testing.T) {
t.Skip("bor due to burn contract")
backend, chain := newTestBackend(t) backend, chain := newTestBackend(t)
client, _ := backend.Attach() client, _ := backend.Attach()
defer backend.Close() defer backend.Close()
......
...@@ -89,6 +89,8 @@ func generateTestChain() (*core.Genesis, []*types.Block) { ...@@ -89,6 +89,8 @@ func generateTestChain() (*core.Genesis, []*types.Block) {
} }
func TestGethClient(t *testing.T) { func TestGethClient(t *testing.T) {
t.Skip("bor due to burn contract")
backend, _ := newTestBackend(t) backend, _ := newTestBackend(t)
client, err := backend.Attach() client, err := backend.Attach()
if err != nil { if err != nil {
......
...@@ -57,6 +57,9 @@ const ( ...@@ -57,6 +57,9 @@ const (
txChanSize = 4096 txChanSize = 4096
// chainHeadChanSize is the size of channel listening to ChainHeadEvent. // chainHeadChanSize is the size of channel listening to ChainHeadEvent.
chainHeadChanSize = 10 chainHeadChanSize = 10
// chain2HeadChanSize is the size of channel listening to Chain2HeadEvent.
chain2HeadChanSize = 10
) )
// backend encompasses the bare-minimum functionality needed for ethstats reporting // backend encompasses the bare-minimum functionality needed for ethstats reporting
...@@ -68,6 +71,9 @@ type backend interface { ...@@ -68,6 +71,9 @@ type backend interface {
GetTd(ctx context.Context, hash common.Hash) *big.Int GetTd(ctx context.Context, hash common.Hash) *big.Int
Stats() (pending int, queued int) Stats() (pending int, queued int)
SyncProgress() ethereum.SyncProgress SyncProgress() ethereum.SyncProgress
// Bor
SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription
} }
// fullNodeBackend encompasses the functionality necessary for a full node // fullNodeBackend encompasses the functionality necessary for a full node
...@@ -96,6 +102,9 @@ type Service struct { ...@@ -96,6 +102,9 @@ type Service struct {
headSub event.Subscription headSub event.Subscription
txSub event.Subscription txSub event.Subscription
//bor related sub
chain2headSub event.Subscription
} }
// connWrapper is a wrapper to prevent concurrent-write or concurrent-read on the // connWrapper is a wrapper to prevent concurrent-write or concurrent-read on the
...@@ -195,7 +204,9 @@ func (s *Service) Start() error { ...@@ -195,7 +204,9 @@ func (s *Service) Start() error {
s.headSub = s.backend.SubscribeChainHeadEvent(chainHeadCh) s.headSub = s.backend.SubscribeChainHeadEvent(chainHeadCh)
txEventCh := make(chan core.NewTxsEvent, txChanSize) txEventCh := make(chan core.NewTxsEvent, txChanSize)
s.txSub = s.backend.SubscribeNewTxsEvent(txEventCh) s.txSub = s.backend.SubscribeNewTxsEvent(txEventCh)
go s.loop(chainHeadCh, txEventCh) chain2HeadCh := make(chan core.Chain2HeadEvent, chain2HeadChanSize)
s.chain2headSub = s.backend.SubscribeChain2HeadEvent(chain2HeadCh)
go s.loop(chainHeadCh, chain2HeadCh, txEventCh)
log.Info("Stats daemon started") log.Info("Stats daemon started")
return nil return nil
...@@ -211,12 +222,13 @@ func (s *Service) Stop() error { ...@@ -211,12 +222,13 @@ func (s *Service) Stop() error {
// loop keeps trying to connect to the netstats server, reporting chain events // loop keeps trying to connect to the netstats server, reporting chain events
// until termination. // until termination.
func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core.NewTxsEvent) { func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, chain2HeadCh chan core.Chain2HeadEvent, txEventCh chan core.NewTxsEvent) {
// Start a goroutine that exhausts the subscriptions to avoid events piling up // Start a goroutine that exhausts the subscriptions to avoid events piling up
var ( var (
quitCh = make(chan struct{}) quitCh = make(chan struct{})
headCh = make(chan *types.Block, 1) headCh = make(chan *types.Block, 1)
txCh = make(chan struct{}, 1) txCh = make(chan struct{}, 1)
head2Ch = make(chan core.Chain2HeadEvent, 100)
) )
go func() { go func() {
var lastTx mclock.AbsTime var lastTx mclock.AbsTime
...@@ -231,6 +243,13 @@ func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core ...@@ -231,6 +243,13 @@ func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core
default: default:
} }
// Notify of chain2head events, but drop if too frequent
case chain2head := <-chain2HeadCh:
select {
case head2Ch <- chain2head:
default:
}
// Notify of new transaction events, but drop if too frequent // Notify of new transaction events, but drop if too frequent
case <-txEventCh: case <-txEventCh:
if time.Duration(mclock.Now()-lastTx) < time.Second { if time.Duration(mclock.Now()-lastTx) < time.Second {
...@@ -333,6 +352,12 @@ func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core ...@@ -333,6 +352,12 @@ func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core
if err = s.reportPending(conn); err != nil { if err = s.reportPending(conn); err != nil {
log.Warn("Post-block transaction stats report failed", "err", err) log.Warn("Post-block transaction stats report failed", "err", err)
} }
case chain2head := <-head2Ch:
if err = s.reportChain2Head(conn, &chain2head); err != nil {
log.Warn("Reorg stats report failed", "err", err)
}
case <-txCh: case <-txCh:
if err = s.reportPending(conn); err != nil { if err = s.reportPending(conn); err != nil {
log.Warn("Transaction stats report failed", "err", err) log.Warn("Transaction stats report failed", "err", err)
...@@ -750,6 +775,49 @@ func (s *Service) reportPending(conn *connWrapper) error { ...@@ -750,6 +775,49 @@ func (s *Service) reportPending(conn *connWrapper) error {
return conn.WriteJSON(report) return conn.WriteJSON(report)
} }
type blockStub struct {
Hash string `json:"hash"`
Number uint64 `json:"number"`
ParentHash string `json:"parent_hash"`
}
func createStub(b *types.Block) *blockStub {
s := &blockStub{
Hash: b.Hash().String(),
ParentHash: b.ParentHash().String(),
Number: b.NumberU64(),
}
return s
}
type ChainHeadEvent struct {
NewChain []*blockStub `json:"added"`
OldChain []*blockStub `json:"removed"`
Type string `json:"type"`
}
// reportChain2Head checks for reorg and sends current head to stats server.
func (s *Service) reportChain2Head(conn *connWrapper, chain2HeadData *core.Chain2HeadEvent) error {
chainHeadEvent := ChainHeadEvent{
Type: chain2HeadData.Type,
}
for _, block := range chain2HeadData.NewChain {
chainHeadEvent.NewChain = append(chainHeadEvent.NewChain, createStub(block))
}
for _, block := range chain2HeadData.OldChain {
chainHeadEvent.OldChain = append(chainHeadEvent.OldChain, createStub(block))
}
stats := map[string]interface{}{
"id": s.node,
"event": chainHeadEvent,
}
report := map[string][]interface{}{
"emit": {"headEvent", stats},
}
return conn.WriteJSON(report)
}
// nodeStats is the information to report about the local node. // nodeStats is the information to report about the local node.
type nodeStats struct { type nodeStats struct {
Active bool `json:"active"` Active bool `json:"active"`
......
...@@ -53,6 +53,7 @@ require ( ...@@ -53,6 +53,7 @@ require (
github.com/mattn/go-colorable v0.1.8 github.com/mattn/go-colorable v0.1.8
github.com/mattn/go-isatty v0.0.12 github.com/mattn/go-isatty v0.0.12
github.com/mitchellh/cli v1.1.2 github.com/mitchellh/cli v1.1.2
github.com/mitchellh/go-grpc-net-conn v0.0.0-20200427190222-eb030e4876f0 // indirect
github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-homedir v1.1.0
github.com/naoina/go-stringutil v0.1.0 // indirect github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
......
...@@ -33,7 +33,6 @@ github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSW ...@@ -33,7 +33,6 @@ github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSW
github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g= github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g=
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
github.com/Azure/go-autorest/autorest/mocks v0.3.0 h1:qJumjCaCudz+OcqE9/XtEPfvtOjOmKaui4EOpFI6zZc=
github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM= github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM=
github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY= github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY=
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
...@@ -375,6 +374,8 @@ github.com/mitchellh/cli v1.1.2 h1:PvH+lL2B7IQ101xQL63Of8yFS2y+aDlsFcsqNc+u/Kw= ...@@ -375,6 +374,8 @@ github.com/mitchellh/cli v1.1.2 h1:PvH+lL2B7IQ101xQL63Of8yFS2y+aDlsFcsqNc+u/Kw=
github.com/mitchellh/cli v1.1.2/go.mod h1:6iaV0fGdElS6dPBx0EApTxHrcWvmJphyh2n8YBLPPZ4= github.com/mitchellh/cli v1.1.2/go.mod h1:6iaV0fGdElS6dPBx0EApTxHrcWvmJphyh2n8YBLPPZ4=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/go-grpc-net-conn v0.0.0-20200427190222-eb030e4876f0 h1:oZuel4h7224ILBLg2SlTxdaMYXDyqcVfL4Cg1PJQHZs=
github.com/mitchellh/go-grpc-net-conn v0.0.0-20200427190222-eb030e4876f0/go.mod h1:ZCzL0JMR6qfm7VrDC8HGwVtPA8D2Ijc/edUSBw58x94=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
...@@ -732,6 +733,7 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac ...@@ -732,6 +733,7 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.28.1/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k= google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k=
......
package main package cli
import "github.com/mitchellh/cli" import "github.com/mitchellh/cli"
......
package main package cli
import ( import (
"fmt" "fmt"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/command/flagset"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/internal/cli/flagset"
) )
type AccountImportCommand struct { type AccountImportCommand struct {
......
package main package cli
import ( import (
"fmt" "fmt"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/command/flagset" "github.com/ethereum/go-ethereum/internal/cli/flagset"
) )
type AccountListCommand struct { type AccountListCommand struct {
......
package main package cli
import ( import (
"fmt" "fmt"
"github.com/ethereum/go-ethereum/command/flagset" "github.com/ethereum/go-ethereum/internal/cli/flagset"
) )
type AccountNewCommand struct { type AccountNewCommand struct {
......
package main package cli
import ( import (
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
......
package main package cli
import ( import (
"context" "context"
"fmt" "fmt"
"strconv" "strconv"
"github.com/ethereum/go-ethereum/command/flagset" "github.com/ethereum/go-ethereum/internal/cli/flagset"
"github.com/ethereum/go-ethereum/command/server/proto" "github.com/ethereum/go-ethereum/internal/cli/server/proto"
) )
// ChainSetHeadCommand is the command to group the peers commands // ChainSetHeadCommand is the command to group the peers commands
......
package cli
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/internal/cli/flagset"
"github.com/ethereum/go-ethereum/internal/cli/server/proto"
)
// ChainWatchCommand is the command to group the peers commands
type ChainWatchCommand struct {
*Meta2
}
// Help implements the cli.Command interface
func (c *ChainWatchCommand) Help() string {
return `Usage: bor chain watch
This command is used to view the chainHead, reorg and fork events in real-time`
}
func (c *ChainWatchCommand) Flags() *flagset.Flagset {
flags := c.NewFlagSet("chain watch")
return flags
}
// Synopsis implements the cli.Command interface
func (c *ChainWatchCommand) Synopsis() string {
return "Watch the chainHead, reorg and fork events in real-time"
}
// Run implements the cli.Command interface
func (c *ChainWatchCommand) Run(args []string) int {
flags := c.Flags()
if err := flags.Parse(args); err != nil {
c.UI.Error(err.Error())
return 1
}
borClt, err := c.BorConn()
if err != nil {
c.UI.Error(err.Error())
return 1
}
sub, err := borClt.ChainWatch(context.Background(), &proto.ChainWatchRequest{})
if err != nil {
c.UI.Error(err.Error())
return 1
}
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
go func() {
<-signalCh
sub.CloseSend()
}()
for {
msg, err := sub.Recv()
if err != nil {
// if err == EOF if finished on the other side
c.UI.Output(err.Error())
break
}
c.UI.Output(formatHeadEvent(msg))
}
return 0
}
func formatHeadEvent(msg *proto.ChainWatchResponse) string {
var out string
if msg.Type == core.Chain2HeadCanonicalEvent {
out = fmt.Sprintf("Block Added : %v", msg.Newchain)
} else if msg.Type == core.Chain2HeadForkEvent {
out = fmt.Sprintf("New Fork Block : %v", msg.Newchain)
} else if msg.Type == core.Chain2HeadReorgEvent {
out = fmt.Sprintf("Reorg Detected \nAdded : %v \nRemoved : %v", msg.Newchain, msg.Oldchain)
}
return out
}
package main package cli
import ( import (
"fmt" "fmt"
"os" "os"
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/command/flagset" "github.com/ethereum/go-ethereum/internal/cli/flagset"
"github.com/ethereum/go-ethereum/command/server" "github.com/ethereum/go-ethereum/internal/cli/server"
"github.com/ethereum/go-ethereum/command/server/proto" "github.com/ethereum/go-ethereum/internal/cli/server/proto"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
"github.com/ryanuber/columnize" "github.com/ryanuber/columnize"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
func main() {
os.Exit(Run(os.Args[1:]))
}
func Run(args []string) int { func Run(args []string) int {
commands := commands() commands := commands()
...@@ -69,6 +65,11 @@ func commands() map[string]cli.CommandFactory { ...@@ -69,6 +65,11 @@ func commands() map[string]cli.CommandFactory {
UI: ui, UI: ui,
}, nil }, nil
}, },
"chain watch": func() (cli.Command, error) {
return &ChainWatchCommand{
Meta2: meta2,
}, nil
},
"chain sethead": func() (cli.Command, error) { "chain sethead": func() (cli.Command, error) {
return &ChainSetHeadCommand{ return &ChainSetHeadCommand{
Meta2: meta2, Meta2: meta2,
...@@ -119,6 +120,11 @@ func commands() map[string]cli.CommandFactory { ...@@ -119,6 +120,11 @@ func commands() map[string]cli.CommandFactory {
Meta2: meta2, Meta2: meta2,
}, nil }, nil
}, },
"status": func() (cli.Command, error) {
return &StatusCommand{
Meta2: meta2,
}, nil
},
} }
} }
......
package main package cli
// Based on https://github.com/hashicorp/nomad/blob/main/command/operator_debug.go // Based on https://github.com/hashicorp/nomad/blob/main/command/operator_debug.go
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"archive/tar" "archive/tar"
"compress/gzip" "compress/gzip"
"context" "context"
"encoding/hex"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
...@@ -17,8 +16,12 @@ import ( ...@@ -17,8 +16,12 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/ethereum/go-ethereum/command/flagset" "github.com/ethereum/go-ethereum/internal/cli/flagset"
"github.com/ethereum/go-ethereum/command/server/proto" "github.com/ethereum/go-ethereum/internal/cli/server/proto"
"github.com/golang/protobuf/jsonpb"
gproto "github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/empty"
grpc_net_conn "github.com/mitchellh/go-grpc-net-conn"
) )
type DebugCommand struct { type DebugCommand struct {
...@@ -118,16 +121,35 @@ func (d *DebugCommand) Run(args []string) int { ...@@ -118,16 +121,35 @@ func (d *DebugCommand) Run(args []string) int {
req.Type = proto.PprofRequest_LOOKUP req.Type = proto.PprofRequest_LOOKUP
req.Profile = profile req.Profile = profile
} }
resp, err := clt.Pprof(ctx, req) stream, err := clt.Pprof(ctx, req)
if err != nil { if err != nil {
return err return err
} }
// write file // wait for open request
raw, err := hex.DecodeString(resp.Payload) msg, err := stream.Recv()
if err != nil { if err != nil {
return err return err
} }
if err := ioutil.WriteFile(filepath.Join(tmp, filename+".prof"), raw, 0755); err != nil { if _, ok := msg.Event.(*proto.PprofResponse_Open_); !ok {
return fmt.Errorf("expected open message")
}
// create the stream
conn := &grpc_net_conn.Conn{
Stream: stream,
Response: &proto.PprofResponse_Input{},
Decode: grpc_net_conn.SimpleDecoder(func(msg gproto.Message) *[]byte {
return &msg.(*proto.PprofResponse_Input).Data
}),
}
file, err := os.OpenFile(filepath.Join(tmp, filename+".prof"), os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return err
}
defer file.Close()
if _, err := io.Copy(file, conn); err != nil {
return err return err
} }
return nil return nil
...@@ -148,6 +170,25 @@ func (d *DebugCommand) Run(args []string) int { ...@@ -148,6 +170,25 @@ func (d *DebugCommand) Run(args []string) int {
} }
} }
// append the status
{
statusResp, err := clt.Status(ctx, &empty.Empty{})
if err != nil {
d.UI.Output(fmt.Sprintf("Failed to get status: %v", err))
return 1
}
m := jsonpb.Marshaler{}
data, err := m.MarshalToString(statusResp)
if err != nil {
d.UI.Output(err.Error())
return 1
}
if err := ioutil.WriteFile(filepath.Join(tmp, "status.json"), []byte(data), 0644); err != nil {
d.UI.Output(fmt.Sprintf("Failed to write status: %v", err))
return 1
}
}
// Exit before archive if output directory was specified // Exit before archive if output directory was specified
if d.output != "" { if d.output != "" {
d.UI.Output(fmt.Sprintf("Created debug directory: %s", tmp)) d.UI.Output(fmt.Sprintf("Created debug directory: %s", tmp))
......
package main package cli
import ( import (
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
...@@ -17,11 +17,11 @@ func (c *PeersCommand) Help() string { ...@@ -17,11 +17,11 @@ func (c *PeersCommand) Help() string {
List the connected peers: List the connected peers:
$ bor account new $ bor peers list
Add a new peer by enode: Add a new peer by enode:
$ bor account import $ bor peers add <enode>
Remove a connected peer by enode: Remove a connected peer by enode:
......
package main package cli
import ( import (
"context" "context"
"github.com/ethereum/go-ethereum/command/flagset" "github.com/ethereum/go-ethereum/internal/cli/flagset"
"github.com/ethereum/go-ethereum/command/server/proto" "github.com/ethereum/go-ethereum/internal/cli/server/proto"
) )
// PeersAddCommand is the command to group the peers commands // PeersAddCommand is the command to group the peers commands
......