mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
Merge pull request #1383 from maticnetwork/v1.5.3-beta-candidate
v1.5.3 candidate
This commit is contained in:
commit
569eb7bb5a
21 changed files with 300 additions and 42 deletions
3
.github/workflows/packager_deb.yml
vendored
3
.github/workflows/packager_deb.yml
vendored
|
|
@ -82,6 +82,9 @@ jobs:
|
||||||
- name: Building bor for arm64
|
- name: Building bor for arm64
|
||||||
run: GOARCH=arm64 GOOS=linux CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ CGO_ENABLED=1 go build -o build/bin/bor ./cmd/cli/main.go
|
run: GOARCH=arm64 GOOS=linux CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ CGO_ENABLED=1 go build -o build/bin/bor ./cmd/cli/main.go
|
||||||
|
|
||||||
|
- name: Copying necessary binary post arm64 build
|
||||||
|
run: cp -rp build/bin/bor packaging/deb/bor/usr/bin/
|
||||||
|
|
||||||
# Control file for arm64 creation
|
# Control file for arm64 creation
|
||||||
- name: create control file
|
- name: create control file
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
heimdallAPIBodyLimit = 128 * 1024 * 1024 // 128 MB
|
||||||
stateFetchLimit = 50
|
stateFetchLimit = 50
|
||||||
apiHeimdallTimeout = 5 * time.Second
|
apiHeimdallTimeout = 5 * time.Second
|
||||||
retryCall = 5 * time.Second
|
retryCall = 5 * time.Second
|
||||||
|
|
@ -455,8 +456,11 @@ func internalFetch(ctx context.Context, client http.Client, u *url.URL) ([]byte,
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Limit the number of bytes read from the response body
|
||||||
|
limitedBody := http.MaxBytesReader(nil, res.Body, heimdallAPIBodyLimit)
|
||||||
|
|
||||||
// get response
|
// get response
|
||||||
body, err := io.ReadAll(res.Body)
|
body, err := io.ReadAll(limitedBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2374,6 +2374,20 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
|
||||||
status WriteStatus
|
status WriteStatus
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Before the actual db insertion happens, verify the block against the whitelisted
|
||||||
|
// milestone and checkpoint. This is to prevent a race condition where a milestone
|
||||||
|
// or checkpoint was whitelisted while the block execution happened (and wasn't
|
||||||
|
// available sometime before) and the block turns out to be inavlid (i.e. not
|
||||||
|
// honouring the milestone or checkpoint). Use the block itself as current block
|
||||||
|
// so that it's considered as a `past` chain and the validation doesn't get bypassed.
|
||||||
|
isValid, err = bc.forker.ValidateReorg(block.Header(), []*types.Header{block.Header()})
|
||||||
|
if err != nil {
|
||||||
|
return it.index, err
|
||||||
|
}
|
||||||
|
if !isValid {
|
||||||
|
return it.index, whitelist.ErrMismatch
|
||||||
|
}
|
||||||
|
|
||||||
if !setHead {
|
if !setHead {
|
||||||
// Don't set the head, only insert the block
|
// Don't set the head, only insert the block
|
||||||
_, err = bc.writeBlockWithState(block, receipts, logs, statedb)
|
_, err = bc.writeBlockWithState(block, receipts, logs, statedb)
|
||||||
|
|
|
||||||
|
|
@ -618,7 +618,7 @@ func makeBlockChainWithGenesis(genesis *Genesis, n int, engine consensus.Engine,
|
||||||
return db, blocks
|
return db, blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeBlockChain creates a deterministic chain of blocks rooted at parent with fake invalid transactions.
|
// makeFakeNonEmptyBlockChain creates a deterministic chain of blocks rooted at parent with fake invalid transactions.
|
||||||
func makeFakeNonEmptyBlockChain(parent *types.Block, n int, engine consensus.Engine, db ethdb.Database, seed int, numTx int) []*types.Block {
|
func makeFakeNonEmptyBlockChain(parent *types.Block, n int, engine consensus.Engine, db ethdb.Database, seed int, numTx int) []*types.Block {
|
||||||
blocks, _ := GenerateChain(params.TestChainConfig, parent, engine, db, n, func(i int, b *BlockGen) {
|
blocks, _ := GenerateChain(params.TestChainConfig, parent, engine, db, n, func(i int, b *BlockGen) {
|
||||||
addr := common.Address{0: byte(seed), 19: byte(i)}
|
addr := common.Address{0: byte(seed), 19: byte(i)}
|
||||||
|
|
|
||||||
|
|
@ -418,7 +418,6 @@ func (s *StateDB) ApplyMVWriteSet(writes []blockstm.WriteDescriptor) {
|
||||||
|
|
||||||
switch path.GetSubpath() {
|
switch path.GetSubpath() {
|
||||||
case BalancePath:
|
case BalancePath:
|
||||||
// todo: @anshalshukla || @cffls - check balance change reason
|
|
||||||
s.SetBalance(addr, sr.GetBalance(addr), tracing.BalanceChangeUnspecified)
|
s.SetBalance(addr, sr.GetBalance(addr), tracing.BalanceChangeUnspecified)
|
||||||
case NoncePath:
|
case NoncePath:
|
||||||
s.SetNonce(addr, sr.GetNonce(addr))
|
s.SetNonce(addr, sr.GetNonce(addr))
|
||||||
|
|
@ -1095,9 +1094,6 @@ func (s *StateDB) createObject(addr common.Address) *stateObject {
|
||||||
// consensus bug eventually.
|
// consensus bug eventually.
|
||||||
func (s *StateDB) CreateAccount(addr common.Address) {
|
func (s *StateDB) CreateAccount(addr common.Address) {
|
||||||
s.createObject(addr)
|
s.createObject(addr)
|
||||||
// todo: @anshalshukla || @cffls
|
|
||||||
// Check the below MV Write, balance path change have been removed
|
|
||||||
MVWrite(s, blockstm.NewAddressKey(addr))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateContract is used whenever a contract is created. This may be preceded
|
// CreateContract is used whenever a contract is created. This may be preceded
|
||||||
|
|
@ -1107,13 +1103,14 @@ func (s *StateDB) CreateAccount(addr common.Address) {
|
||||||
// correctly handle EIP-6780 'delete-in-same-transaction' logic.
|
// correctly handle EIP-6780 'delete-in-same-transaction' logic.
|
||||||
func (s *StateDB) CreateContract(addr common.Address) {
|
func (s *StateDB) CreateContract(addr common.Address) {
|
||||||
obj := s.getStateObject(addr)
|
obj := s.getStateObject(addr)
|
||||||
|
if obj != nil {
|
||||||
|
obj = s.mvRecordWritten(obj)
|
||||||
|
}
|
||||||
if !obj.newContract {
|
if !obj.newContract {
|
||||||
obj.newContract = true
|
obj.newContract = true
|
||||||
s.journal.append(createContractChange{account: addr})
|
s.journal.append(createContractChange{account: addr})
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: @anshalshukla || @cffls
|
|
||||||
// Check the below MV Write, balance path change have been removed
|
|
||||||
MVWrite(s, blockstm.NewAddressKey(addr))
|
MVWrite(s, blockstm.NewAddressKey(addr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -813,6 +813,33 @@ func TestMVHashMapReadWriteDelete(t *testing.T) {
|
||||||
assert.Equal(t, uint256.NewInt(0), b)
|
assert.Equal(t, uint256.NewInt(0), b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMVHashMapCreateContract(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := NewDatabase(rawdb.NewMemoryDatabase())
|
||||||
|
mvhm := blockstm.MakeMVHashMap()
|
||||||
|
s, _ := NewWithMVHashmap(common.Hash{}, db, nil, mvhm)
|
||||||
|
|
||||||
|
states := []*StateDB{s}
|
||||||
|
|
||||||
|
// Create copies of the original state for each transition
|
||||||
|
for i := 1; i <= 4; i++ {
|
||||||
|
sCopy := s.Copy()
|
||||||
|
sCopy.txIndex = i
|
||||||
|
states = append(states, sCopy)
|
||||||
|
}
|
||||||
|
|
||||||
|
addr := common.HexToAddress("0x01")
|
||||||
|
states[0].SetBalance(addr, uint256.NewInt(100), tracing.BalanceChangeTransfer)
|
||||||
|
states[0].FlushMVWriteSet()
|
||||||
|
|
||||||
|
states[1].CreateContract(addr)
|
||||||
|
states[1].FlushMVWriteSet()
|
||||||
|
|
||||||
|
b := states[1].GetBalance(addr)
|
||||||
|
assert.Equal(t, uint256.NewInt(100), b)
|
||||||
|
}
|
||||||
|
|
||||||
func TestMVHashMapRevert(t *testing.T) {
|
func TestMVHashMapRevert(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ func (b *EthAPIBackend) GetRootHash(ctx context.Context, starBlockNr uint64, end
|
||||||
return root, nil
|
return root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRootHash returns root hash for given start and end block
|
// GetVoteOnHash returns the vote on hash
|
||||||
func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, endBlockNr uint64, hash string, milestoneId string) (bool, error) {
|
func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, endBlockNr uint64, hash string, milestoneId string) (bool, error) {
|
||||||
var api *bor.API
|
var api *bor.API
|
||||||
|
|
||||||
|
|
|
||||||
4
go.mod
4
go.mod
|
|
@ -36,7 +36,7 @@ require (
|
||||||
github.com/fsnotify/fsnotify v1.7.0
|
github.com/fsnotify/fsnotify v1.7.0
|
||||||
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08
|
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08
|
||||||
github.com/gofrs/flock v0.8.1
|
github.com/gofrs/flock v0.8.1
|
||||||
github.com/golang-jwt/jwt/v4 v4.5.0
|
github.com/golang-jwt/jwt/v4 v4.5.1
|
||||||
github.com/golang/mock v1.6.0
|
github.com/golang/mock v1.6.0
|
||||||
github.com/golang/protobuf v1.5.4
|
github.com/golang/protobuf v1.5.4
|
||||||
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb
|
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb
|
||||||
|
|
@ -65,7 +65,7 @@ require (
|
||||||
github.com/kylelemons/godebug v1.1.0
|
github.com/kylelemons/godebug v1.1.0
|
||||||
github.com/maticnetwork/crand v1.0.2
|
github.com/maticnetwork/crand v1.0.2
|
||||||
github.com/maticnetwork/heimdall v1.0.7
|
github.com/maticnetwork/heimdall v1.0.7
|
||||||
github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53
|
github.com/maticnetwork/polyproto v0.0.4
|
||||||
github.com/mattn/go-colorable v0.1.13
|
github.com/mattn/go-colorable v0.1.13
|
||||||
github.com/mattn/go-isatty v0.0.20
|
github.com/mattn/go-isatty v0.0.20
|
||||||
github.com/mitchellh/cli v1.1.5
|
github.com/mitchellh/cli v1.1.5
|
||||||
|
|
|
||||||
6
go.sum
6
go.sum
|
|
@ -1292,8 +1292,9 @@ github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzw
|
||||||
github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
||||||
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||||
github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||||
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
|
|
||||||
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||||
|
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
|
||||||
|
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||||
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
|
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||||
|
|
@ -1706,8 +1707,9 @@ github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxp
|
||||||
github.com/maticnetwork/heimdall v1.0.4/go.mod h1:Xh7KFvtbs/SVNjOI8IgYmk6JdzYx89eU/XUwH0AgHLs=
|
github.com/maticnetwork/heimdall v1.0.4/go.mod h1:Xh7KFvtbs/SVNjOI8IgYmk6JdzYx89eU/XUwH0AgHLs=
|
||||||
github.com/maticnetwork/heimdall v1.0.7 h1:QStn+hbZKxfE+PqecaorA/uATDPuQoi+U9Z7IIonb60=
|
github.com/maticnetwork/heimdall v1.0.7 h1:QStn+hbZKxfE+PqecaorA/uATDPuQoi+U9Z7IIonb60=
|
||||||
github.com/maticnetwork/heimdall v1.0.7/go.mod h1:+ANI5+VV28ahwfdl7oMzrcNwaTEs1Fn6z39BqBGcvaA=
|
github.com/maticnetwork/heimdall v1.0.7/go.mod h1:+ANI5+VV28ahwfdl7oMzrcNwaTEs1Fn6z39BqBGcvaA=
|
||||||
github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53 h1:PjYV+lghs106JKkrYgOnrsfDLoTc11BxZd4rUa4Rus4=
|
|
||||||
github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
|
github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
|
||||||
|
github.com/maticnetwork/polyproto v0.0.4 h1:qQ/qwcO6UNGS4mJlzlLJn1AUMfJK9Rqmf1v+KJgnPsk=
|
||||||
|
github.com/maticnetwork/polyproto v0.0.4/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
|
||||||
github.com/maticnetwork/tendermint v0.33.0 h1:f+vORM02BoUOlCvnu3Zjw5rv6l6JSNVchWjH03rUuR8=
|
github.com/maticnetwork/tendermint v0.33.0 h1:f+vORM02BoUOlCvnu3Zjw5rv6l6JSNVchWjH03rUuR8=
|
||||||
github.com/maticnetwork/tendermint v0.33.0/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk=
|
github.com/maticnetwork/tendermint v0.33.0/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk=
|
||||||
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
|
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo $peers
|
echo "$peers"
|
||||||
echo $block
|
echo "$block"
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ do
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( $balance > $balanceInit )); then
|
if (( balance > balanceInit )); then
|
||||||
if [ $stateSyncFound != "true" ]; then
|
if [ "$stateSyncFound" != "true" ]; then
|
||||||
stateSyncTime=$(( SECONDS - start_time ))
|
stateSyncTime=$(( SECONDS - start_time ))
|
||||||
stateSyncFound="true"
|
stateSyncFound="true"
|
||||||
fi
|
fi
|
||||||
|
|
@ -27,18 +27,18 @@ do
|
||||||
|
|
||||||
checkpointID=$(curl -sL http://localhost:1317/checkpoints/latest | jq .result.id)
|
checkpointID=$(curl -sL http://localhost:1317/checkpoints/latest | jq .result.id)
|
||||||
|
|
||||||
if [ $checkpointID != "null" ]; then
|
if [ "$checkpointID" != "null" ]; then
|
||||||
if [ $checkpointFound != "true" ]; then
|
if [ "$checkpointFound" != "true" ]; then
|
||||||
checkpointTime=$(( SECONDS - start_time ))
|
checkpointTime=$(( SECONDS - start_time ))
|
||||||
checkpointFound="true"
|
checkpointFound="true"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $stateSyncFound == "true" ] && [ $checkpointFound == "true" ]; then
|
if [ "$stateSyncFound" == "true" ] && [ "$checkpointFound" == "true" ]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
echo "Both state sync and checkpoint went through. All tests have passed!"
|
echo "Both state sync and checkpoint went through. All tests have passed!"
|
||||||
echo "Time taken for state sync: $(printf '%02dm:%02ds\n' $(($stateSyncTime%3600/60)) $(($stateSyncTime%60)))"
|
echo "Time taken for state sync: $(printf '%02dm:%02ds\n' $((stateSyncTime%3600/60)) $((stateSyncTime%60)))"
|
||||||
echo "Time taken for checkpoint: $(printf '%02dm:%02ds\n' $(($checkpointTime%3600/60)) $(($checkpointTime%60)))"
|
echo "Time taken for checkpoint: $(printf '%02dm:%02ds\n' $((checkpointTime%3600/60)) $((checkpointTime%60)))"
|
||||||
|
|
|
||||||
127
internal/cli/server/api_service.go
Normal file
127
internal/cli/server/api_service.go
Normal file
|
|
@ -0,0 +1,127 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
||||||
|
protobor "github.com/maticnetwork/polyproto/bor"
|
||||||
|
protoutil "github.com/maticnetwork/polyproto/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) GetRootHash(ctx context.Context, req *protobor.GetRootHashRequest) (*protobor.GetRootHashResponse, error) {
|
||||||
|
rootHash, err := s.backend.APIBackend.GetRootHash(ctx, req.StartBlockNumber, req.EndBlockNumber)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &protobor.GetRootHashResponse{RootHash: rootHash}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) GetVoteOnHash(ctx context.Context, req *protobor.GetVoteOnHashRequest) (*protobor.GetVoteOnHashResponse, error) {
|
||||||
|
vote, err := s.backend.APIBackend.GetVoteOnHash(ctx, req.StartBlockNumber, req.EndBlockNumber, req.Hash, req.MilestoneId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &protobor.GetVoteOnHashResponse{Response: vote}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func headerToProtoborHeader(h *types.Header) *protobor.Header {
|
||||||
|
return &protobor.Header{
|
||||||
|
Number: h.Number.Uint64(),
|
||||||
|
ParentHash: protoutil.ConvertHashToH256(h.ParentHash),
|
||||||
|
Time: h.Time,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) {
|
||||||
|
bN, err := getRpcBlockNumberFromString(req.Number)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
header, err := s.backend.APIBackend.HeaderByNumber(ctx, bN)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &protobor.GetHeaderByNumberResponse{Header: headerToProtoborHeader(header)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) BlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) {
|
||||||
|
bN, err := getRpcBlockNumberFromString(req.Number)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
block, err := s.backend.APIBackend.BlockByNumber(ctx, bN)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &protobor.GetBlockByNumberResponse{Block: blockToProtoBlock(block)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func blockToProtoBlock(h *types.Block) *protobor.Block {
|
||||||
|
return &protobor.Block{
|
||||||
|
Header: headerToProtoborHeader(h.Header()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) TransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) {
|
||||||
|
_, _, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
receipts, err := s.backend.APIBackend.GetReceipts(ctx, blockHash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if receipts == nil {
|
||||||
|
return nil, errors.New("no receipts found")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(receipts) <= int(txnIndex) {
|
||||||
|
return nil, errors.New("transaction index out of bounds")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipts[txnIndex])}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) BorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) {
|
||||||
|
receipt, err := s.backend.APIBackend.GetBorBlockReceipt(ctx, protoutil.ConvertH256ToHash(req.Hash))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRpcBlockNumberFromString(blockNumber string) (rpc.BlockNumber, error) {
|
||||||
|
switch blockNumber {
|
||||||
|
case "latest":
|
||||||
|
return rpc.LatestBlockNumber, nil
|
||||||
|
case "earliest":
|
||||||
|
return rpc.EarliestBlockNumber, nil
|
||||||
|
case "pending":
|
||||||
|
return rpc.PendingBlockNumber, nil
|
||||||
|
case "finalized":
|
||||||
|
return rpc.FinalizedBlockNumber, nil
|
||||||
|
case "safe":
|
||||||
|
return rpc.SafeBlockNumber, nil
|
||||||
|
default:
|
||||||
|
blckNum, err := hexutil.DecodeUint64(blockNumber)
|
||||||
|
if err != nil {
|
||||||
|
return rpc.BlockNumber(0), errors.New("invalid block number")
|
||||||
|
}
|
||||||
|
if blckNum > math.MaxInt64 {
|
||||||
|
return rpc.BlockNumber(0), errors.New("block number out of range")
|
||||||
|
}
|
||||||
|
return rpc.BlockNumber(blckNum), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,16 +11,6 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mattn/go-colorable"
|
|
||||||
"github.com/mattn/go-isatty"
|
|
||||||
"go.opentelemetry.io/otel"
|
|
||||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
|
||||||
"go.opentelemetry.io/otel/propagation"
|
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
|
||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
|
||||||
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
|
|
@ -40,14 +30,28 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/metrics/prometheus"
|
"github.com/ethereum/go-ethereum/metrics/prometheus"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
"github.com/mattn/go-colorable"
|
||||||
|
"github.com/mattn/go-isatty"
|
||||||
|
"go.opentelemetry.io/otel"
|
||||||
|
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
||||||
|
"go.opentelemetry.io/otel/propagation"
|
||||||
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
|
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/reflection"
|
||||||
|
|
||||||
// Force-load the tracer engines to trigger registration
|
// Force-load the tracer engines to trigger registration
|
||||||
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
|
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
|
||||||
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
|
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
|
||||||
|
|
||||||
|
protobor "github.com/maticnetwork/polyproto/bor"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
proto.UnimplementedBorServer
|
proto.UnimplementedBorServer
|
||||||
|
protobor.UnimplementedBorApiServer
|
||||||
|
|
||||||
node *node.Node
|
node *node.Node
|
||||||
backend *eth.Ethereum
|
backend *eth.Ethereum
|
||||||
grpcServer *grpc.Server
|
grpcServer *grpc.Server
|
||||||
|
|
@ -439,6 +443,8 @@ func (s *Server) gRPCServerByAddress(addr string) error {
|
||||||
func (s *Server) gRPCServerByListener(listener net.Listener) error {
|
func (s *Server) gRPCServerByListener(listener net.Listener) error {
|
||||||
s.grpcServer = grpc.NewServer(s.withLoggingUnaryInterceptor())
|
s.grpcServer = grpc.NewServer(s.withLoggingUnaryInterceptor())
|
||||||
proto.RegisterBorServer(s.grpcServer, s)
|
proto.RegisterBorServer(s.grpcServer, s)
|
||||||
|
protobor.RegisterBorApiServer(s.grpcServer, s)
|
||||||
|
reflection.Register(s.grpcServer)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := s.grpcServer.Serve(listener); err != nil {
|
if err := s.grpcServer.Serve(listener); err != nil {
|
||||||
|
|
|
||||||
78
internal/cli/server/utils.go
Normal file
78
internal/cli/server/utils.go
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/internal/cli/server/proto"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
|
||||||
|
protobor "github.com/maticnetwork/polyproto/bor"
|
||||||
|
protocommon "github.com/maticnetwork/polyproto/common"
|
||||||
|
protoutil "github.com/maticnetwork/polyproto/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PeerInfoToPeer(info *p2p.PeerInfo) *proto.Peer {
|
||||||
|
return &proto.Peer{
|
||||||
|
Id: info.ID,
|
||||||
|
Enode: info.Enode,
|
||||||
|
Enr: info.ENR,
|
||||||
|
Caps: info.Caps,
|
||||||
|
Name: info.Name,
|
||||||
|
Trusted: info.Network.Trusted,
|
||||||
|
Static: info.Network.Static,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertBloomToProtoBloom(bloom types.Bloom) *protobor.Bloom {
|
||||||
|
return &protobor.Bloom{
|
||||||
|
Bloom: bloom.Bytes(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertLogsToProtoLogs(logs []*types.Log) []*protobor.Log {
|
||||||
|
var protoLogs []*protobor.Log
|
||||||
|
for _, log := range logs {
|
||||||
|
protoLog := &protobor.Log{
|
||||||
|
Address: protoutil.ConvertAddressToH160(log.Address),
|
||||||
|
Topics: ConvertTopicsToProtoTopics(log.Topics),
|
||||||
|
Data: log.Data,
|
||||||
|
BlockNumber: log.BlockNumber,
|
||||||
|
TxHash: protoutil.ConvertHashToH256(log.TxHash),
|
||||||
|
TxIndex: uint64(log.TxIndex),
|
||||||
|
BlockHash: protoutil.ConvertHashToH256(log.BlockHash),
|
||||||
|
Index: uint64(log.Index),
|
||||||
|
Removed: log.Removed,
|
||||||
|
}
|
||||||
|
protoLogs = append(protoLogs, protoLog)
|
||||||
|
}
|
||||||
|
|
||||||
|
return protoLogs
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertTopicsToProtoTopics(topics []common.Hash) []*protocommon.H256 {
|
||||||
|
var protoTopics []*protocommon.H256
|
||||||
|
for _, topic := range topics {
|
||||||
|
protoTopics = append(protoTopics, protoutil.ConvertHashToH256(topic))
|
||||||
|
}
|
||||||
|
|
||||||
|
return protoTopics
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertReceiptToProtoReceipt(receipt *types.Receipt) *protobor.Receipt {
|
||||||
|
return &protobor.Receipt{
|
||||||
|
Type: uint64(receipt.Type),
|
||||||
|
PostState: receipt.PostState,
|
||||||
|
Status: receipt.Status,
|
||||||
|
CumulativeGasUsed: receipt.CumulativeGasUsed,
|
||||||
|
Bloom: ConvertBloomToProtoBloom(receipt.Bloom),
|
||||||
|
Logs: ConvertLogsToProtoLogs(receipt.Logs),
|
||||||
|
TxHash: protoutil.ConvertHashToH256(receipt.TxHash),
|
||||||
|
ContractAddress: protoutil.ConvertAddressToH160(receipt.ContractAddress),
|
||||||
|
GasUsed: receipt.GasUsed,
|
||||||
|
EffectiveGasPrice: receipt.EffectiveGasPrice.Int64(),
|
||||||
|
BlobGasUsed: receipt.BlobGasUsed,
|
||||||
|
BlockHash: protoutil.ConvertHashToH256(receipt.BlockHash),
|
||||||
|
BlockNumber: receipt.BlockNumber.Int64(),
|
||||||
|
TransactionIndex: uint64(receipt.TransactionIndex),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Source: bor
|
Source: bor
|
||||||
Version: 1.5.2
|
Version: 1.5.3
|
||||||
Section: develop
|
Section: develop
|
||||||
Priority: standard
|
Priority: standard
|
||||||
Maintainer: Polygon <release-team@polygon.technology>
|
Maintainer: Polygon <release-team@polygon.technology>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Source: bor
|
Source: bor
|
||||||
Version: 1.5.2
|
Version: 1.5.3
|
||||||
Section: develop
|
Section: develop
|
||||||
Priority: standard
|
Priority: standard
|
||||||
Maintainer: Polygon <release-team@polygon.technology>
|
Maintainer: Polygon <release-team@polygon.technology>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Source: bor-profile
|
Source: bor-profile
|
||||||
Version: 1.5.2
|
Version: 1.5.3
|
||||||
Section: develop
|
Section: develop
|
||||||
Priority: standard
|
Priority: standard
|
||||||
Maintainer: Polygon <release-team@polygon.technology>
|
Maintainer: Polygon <release-team@polygon.technology>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Source: bor-profile
|
Source: bor-profile
|
||||||
Version: 1.5.2
|
Version: 1.5.3
|
||||||
Section: develop
|
Section: develop
|
||||||
Priority: standard
|
Priority: standard
|
||||||
Maintainer: Polygon <release-team@polygon.technology>
|
Maintainer: Polygon <release-team@polygon.technology>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Source: bor-profile
|
Source: bor-profile
|
||||||
Version: 1.5.2
|
Version: 1.5.3
|
||||||
Section: develop
|
Section: develop
|
||||||
Priority: standard
|
Priority: standard
|
||||||
Maintainer: Polygon <release-team@polygon.technology>
|
Maintainer: Polygon <release-team@polygon.technology>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Source: bor-profile
|
Source: bor-profile
|
||||||
Version: 1.5.2
|
Version: 1.5.3
|
||||||
Section: develop
|
Section: develop
|
||||||
Priority: standard
|
Priority: standard
|
||||||
Maintainer: Polygon <release-team@polygon.technology>
|
Maintainer: Polygon <release-team@polygon.technology>
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 1 // Major version component of the current release
|
VersionMajor = 1 // Major version component of the current release
|
||||||
VersionMinor = 5 // Minor version component of the current release
|
VersionMinor = 5 // Minor version component of the current release
|
||||||
VersionPatch = 2 // Patch version component of the current release
|
VersionPatch = 3 // Patch version component of the current release
|
||||||
VersionMeta = "" // Version metadata to append to the version string
|
VersionMeta = "" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue