Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.5.3 candidate #1383

Merged
merged 38 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
91cd4a8
add api calls to bor grpc
anshalshukla Jun 21, 2024
14764d1
save
anshalshukla Jun 29, 2024
48c1d57
save
anshalshukla Jun 29, 2024
1918691
upgrade polyproto version
anshalshukla Sep 10, 2024
6947088
chore: fix function name
luozexuan Oct 10, 2024
63460bd
Merge pull request #1349 from luozexuan/develop
marcello33 Oct 16, 2024
9adec02
Merge pull request #1369 from maticnetwork/master
pratikspatil024 Oct 30, 2024
f08f2ea
chg: some sec fixes
marcello33 Oct 31, 2024
70f3205
Merge pull request #1370 from maticnetwork/mardizzone/fixes
marcello33 Oct 31, 2024
7b4666d
add: logs
marcello33 Nov 7, 2024
aae292c
chg: add logs
marcello33 Nov 8, 2024
5d0d4fb
chg: register reflection for grpc server
marcello33 Nov 8, 2024
af5c327
chg: fix functions' names
marcello33 Nov 8, 2024
af939db
chg: logs
marcello33 Nov 8, 2024
10f5303
chg: remove redundant logs
marcello33 Nov 8, 2024
e219057
chg: sort imports
marcello33 Nov 8, 2024
8c960fd
Merge branch 'develop' of https://github.com/maticnetwork/bor into bo…
marcello33 Nov 8, 2024
4221228
add: deps
marcello33 Nov 8, 2024
2af775c
fix: build
marcello33 Nov 8, 2024
a4eb8db
fix: lint
marcello33 Nov 8, 2024
7a85412
fix: lint
marcello33 Nov 8, 2024
59b085a
Merge pull request #1373 from maticnetwork/bor-grpc
marcello33 Nov 13, 2024
9cb6fca
chg: handle edge cases with string blockNumber
marcello33 Nov 13, 2024
927db07
chg: switch blockNumber
marcello33 Nov 13, 2024
baa8a2b
cgh: fix rpc blockNumber and bash warnings
marcello33 Nov 13, 2024
32138d7
cgh: fix possible out of range on blockNumber
marcello33 Nov 13, 2024
0634d11
cgh: use geth for maxInt
marcello33 Nov 13, 2024
10d9594
chg: try blocks hex ecnoding
marcello33 Nov 14, 2024
b6efb3f
chg: bump polyproto
marcello33 Nov 14, 2024
6d4d96b
build(deps): bump github.com/golang-jwt/jwt/v4 from 4.5.0 to 4.5.1 (#…
dependabot[bot] Nov 14, 2024
4c4185c
Merge pull request #1374 from maticnetwork/mardizzone/grpc
marcello33 Nov 14, 2024
ee5318b
core: validate chain before writing block (#1319)
manav2401 Nov 18, 2024
b45347a
Wrong architecture binary ended up in arm64
djpolygon Dec 5, 2024
7869600
Updating verbage
djpolygon Dec 5, 2024
d227610
Merge pull request #1380 from maticnetwork/djpolygon/SPEC-559
marcello33 Dec 10, 2024
d509034
chg: update version
marcello33 Dec 10, 2024
8f75330
chg: bump stable version
marcello33 Dec 11, 2024
6c75359
Fix incorrect balance when CreateContract is used in block-stm (#1382)
cffls Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/packager_deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ jobs:
- 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

- name: Copying necessary binary post arm64 build
run: cp -rp build/bin/bor packaging/deb/bor/usr/bin/

# Control file for arm64 creation
- name: create control file
run: |
Expand Down
12 changes: 8 additions & 4 deletions consensus/bor/heimdall/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ var (
)

const (
stateFetchLimit = 50
apiHeimdallTimeout = 5 * time.Second
retryCall = 5 * time.Second
heimdallAPIBodyLimit = 128 * 1024 * 1024 // 128 MB
stateFetchLimit = 50
apiHeimdallTimeout = 5 * time.Second
retryCall = 5 * time.Second
)

type StateSyncEventsResponse struct {
Expand Down Expand Up @@ -455,8 +456,11 @@ func internalFetch(ctx context.Context, client http.Client, u *url.URL) ([]byte,
return nil, nil
}

// Limit the number of bytes read from the response body
limitedBody := http.MaxBytesReader(nil, res.Body, heimdallAPIBodyLimit)

// get response
body, err := io.ReadAll(res.Body)
body, err := io.ReadAll(limitedBody)
if err != nil {
return nil, err
}
Expand Down
14 changes: 14 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2374,6 +2374,20 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
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 {
// Don't set the head, only insert the block
_, err = bc.writeBlockWithState(block, receipts, logs, statedb)
Expand Down
2 changes: 1 addition & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ func makeBlockChainWithGenesis(genesis *Genesis, n int, engine consensus.Engine,
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 {
blocks, _ := GenerateChain(params.TestChainConfig, parent, engine, db, n, func(i int, b *BlockGen) {
addr := common.Address{0: byte(seed), 19: byte(i)}
Expand Down
9 changes: 3 additions & 6 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ func (s *StateDB) ApplyMVWriteSet(writes []blockstm.WriteDescriptor) {

switch path.GetSubpath() {
case BalancePath:
// todo: @anshalshukla || @cffls - check balance change reason
s.SetBalance(addr, sr.GetBalance(addr), tracing.BalanceChangeUnspecified)
case NoncePath:
s.SetNonce(addr, sr.GetNonce(addr))
Expand Down Expand Up @@ -1095,9 +1094,6 @@ func (s *StateDB) createObject(addr common.Address) *stateObject {
// consensus bug eventually.
func (s *StateDB) CreateAccount(addr common.Address) {
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
Expand All @@ -1107,13 +1103,14 @@ func (s *StateDB) CreateAccount(addr common.Address) {
// correctly handle EIP-6780 'delete-in-same-transaction' logic.
func (s *StateDB) CreateContract(addr common.Address) {
obj := s.getStateObject(addr)
if obj != nil {
obj = s.mvRecordWritten(obj)
}
if !obj.newContract {
obj.newContract = true
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))
}

Expand Down
27 changes: 27 additions & 0 deletions core/state/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,33 @@ func TestMVHashMapReadWriteDelete(t *testing.T) {
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) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion eth/bor_api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (b *EthAPIBackend) GetRootHash(ctx context.Context, starBlockNr uint64, end
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) {
var api *bor.API

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08
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/protobuf v1.5.4
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb
Expand Down Expand Up @@ -65,7 +65,7 @@ require (
github.com/kylelemons/godebug v1.1.0
github.com/maticnetwork/crand v1.0.2
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-isatty v0.0.20
github.com/mitchellh/cli v1.1.5
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.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.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.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
Expand Down Expand Up @@ -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.7 h1:QStn+hbZKxfE+PqecaorA/uATDPuQoi+U9Z7IIonb60=
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.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/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk=
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/bor_health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ do
fi
done

echo $peers
echo $block
echo "$peers"
echo "$block"
14 changes: 7 additions & 7 deletions integration-tests/smoke_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ do
exit 1
fi

if (( $balance > $balanceInit )); then
if [ $stateSyncFound != "true" ]; then
if (( balance > balanceInit )); then
if [ "$stateSyncFound" != "true" ]; then
stateSyncTime=$(( SECONDS - start_time ))
stateSyncFound="true"
fi
fi

checkpointID=$(curl -sL http://localhost:1317/checkpoints/latest | jq .result.id)

if [ $checkpointID != "null" ]; then
if [ $checkpointFound != "true" ]; then
if [ "$checkpointID" != "null" ]; then
if [ "$checkpointFound" != "true" ]; then
checkpointTime=$(( SECONDS - start_time ))
checkpointFound="true"
fi
fi

if [ $stateSyncFound == "true" ] && [ $checkpointFound == "true" ]; then
if [ "$stateSyncFound" == "true" ] && [ "$checkpointFound" == "true" ]; then
break
fi

done
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 checkpoint: $(printf '%02dm:%02ds\n' $(($checkpointTime%3600/60)) $(($checkpointTime%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)))"
127 changes: 127 additions & 0 deletions internal/cli/server/api_service.go
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading
Loading