Skip to content

Commit e32f197

Browse files
authored
Merge pull request bnb-chain#12 from binance-chain/master_1.1.5
merge master v1.1.5
2 parents 62f333a + 8ff7d53 commit e32f197

File tree

7 files changed

+71
-26
lines changed

7 files changed

+71
-26
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# Changelog
2+
## v1.1.5
3+
BUGFIX
4+
* [\#509](https://github.com/binance-chain/bsc/pull/509) fix graceful shutdown bug
5+
6+
IMPROVEMENT
7+
* [\#536](https://github.com/binance-chain/bsc/pull/536) get diff accounts by replaying block when diff layer not found
8+
* [\#527](https://github.com/binance-chain/bsc/pull/527) improve diffsync protocol in many aspects
9+
* [\#493](https://github.com/binance-chain/bsc/pull/493) implement fast getDiffAccountsWithScope API
10+
211
## v1.1.4
312
Improvement
413
* [\#472](https://github.com/binance-chain/bsc/pull/472) add metrics for contract code bitmap cache

core/blockchain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ func (bc *BlockChain) GetDiffAccounts(blockHash common.Hash) ([]common.Address,
10111011

10121012
if diffLayer == nil {
10131013
if header.TxHash != types.EmptyRootHash {
1014-
return nil, fmt.Errorf("no diff layer found")
1014+
return nil, ErrDiffLayerNotFound
10151015
}
10161016

10171017
return nil, nil

core/error.go

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ var (
3131

3232
// ErrNoGenesis is returned when there is no Genesis Block.
3333
ErrNoGenesis = errors.New("genesis not found in chain")
34+
35+
// ErrDiffLayerNotFound is returned when diff layer not found.
36+
ErrDiffLayerNotFound = errors.New("diff layer not found")
3437
)
3538

3639
// List of evm-call-message pre-checking errors. All state transition messages will

core/state/statedb.go

+8
Original file line numberDiff line numberDiff line change
@@ -1493,3 +1493,11 @@ func (s *StateDB) SlotInAccessList(addr common.Address, slot common.Hash) (addre
14931493
}
14941494
return s.accessList.Contains(addr, slot)
14951495
}
1496+
1497+
func (s *StateDB) GetDirtyAccounts() []common.Address {
1498+
accounts := make([]common.Address, 0, len(s.stateObjectsDirty))
1499+
for account := range s.stateObjectsDirty {
1500+
accounts = append(accounts, account)
1501+
}
1502+
return accounts
1503+
}

internal/ethapi/api.go

+48-23
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,21 @@ func (s *PublicBlockChainAPI) GetDiffAccounts(ctx context.Context, blockNr rpc.B
11141114
return nil, fmt.Errorf("block not found for block number (%d): %v", blockNr, err)
11151115
}
11161116

1117-
return s.b.Chain().GetDiffAccounts(header.Hash())
1117+
accounts, err := s.b.Chain().GetDiffAccounts(header.Hash())
1118+
if err == nil || !errors.Is(err, core.ErrDiffLayerNotFound) {
1119+
return accounts, err
1120+
}
1121+
1122+
// Replay the block when diff layer not found, it is very slow.
1123+
block, err := s.b.BlockByNumber(ctx, blockNr)
1124+
if err != nil {
1125+
return nil, fmt.Errorf("block not found for block number (%d): %v", blockNr, err)
1126+
}
1127+
_, statedb, err := s.replay(ctx, block, nil)
1128+
if err != nil {
1129+
return nil, err
1130+
}
1131+
return statedb.GetDirtyAccounts(), nil
11181132
}
11191133

11201134
func (s *PublicBlockChainAPI) needToReplay(ctx context.Context, block *types.Block, accounts []common.Address) (bool, error) {
@@ -1177,36 +1191,20 @@ func (s *PublicBlockChainAPI) needToReplay(ctx context.Context, block *types.Blo
11771191
return false, nil
11781192
}
11791193

1180-
// GetDiffAccountsWithScope returns detailed changes of some interested accounts in a specific block number.
1181-
func (s *PublicBlockChainAPI) GetDiffAccountsWithScope(ctx context.Context, blockNr rpc.BlockNumber, accounts []common.Address) (*types.DiffAccountsInBlock, error) {
1182-
if s.b.Chain() == nil {
1183-
return nil, fmt.Errorf("blockchain not support get diff accounts")
1184-
}
1185-
1186-
block, err := s.b.BlockByNumber(ctx, blockNr)
1187-
if err != nil {
1188-
return nil, fmt.Errorf("block not found for block number (%d): %v", blockNr, err)
1189-
}
1190-
1194+
func (s *PublicBlockChainAPI) replay(ctx context.Context, block *types.Block, accounts []common.Address) (*types.DiffAccountsInBlock, *state.StateDB, error) {
11911195
result := &types.DiffAccountsInBlock{
1192-
Number: uint64(blockNr),
1196+
Number: block.NumberU64(),
11931197
BlockHash: block.Hash(),
11941198
Transactions: make([]types.DiffAccountsInTx, 0),
11951199
}
11961200

1197-
if needReplay, err := s.needToReplay(ctx, block, accounts); err != nil {
1198-
return nil, err
1199-
} else if !needReplay {
1200-
return result, nil
1201-
}
1202-
12031201
parent, err := s.b.BlockByHash(ctx, block.ParentHash())
12041202
if err != nil {
1205-
return nil, fmt.Errorf("block not found for block number (%d): %v", blockNr-1, err)
1203+
return nil, nil, fmt.Errorf("block not found for block number (%d): %v", block.NumberU64()-1, err)
12061204
}
12071205
statedb, err := s.b.Chain().StateAt(parent.Root())
12081206
if err != nil {
1209-
return nil, fmt.Errorf("state not found for block number (%d): %v", blockNr-1, err)
1207+
return nil, nil, fmt.Errorf("state not found for block number (%d): %v", block.NumberU64()-1, err)
12101208
}
12111209

12121210
accountSet := make(map[common.Address]struct{}, len(accounts))
@@ -1256,7 +1254,7 @@ func (s *PublicBlockChainAPI) GetDiffAccountsWithScope(ctx context.Context, bloc
12561254
}
12571255

12581256
if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil {
1259-
return nil, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
1257+
return nil, nil, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
12601258
}
12611259
statedb.Finalise(vmenv.ChainConfig().IsEIP158(block.Number()))
12621260

@@ -1275,7 +1273,34 @@ func (s *PublicBlockChainAPI) GetDiffAccountsWithScope(ctx context.Context, bloc
12751273
}
12761274
}
12771275

1278-
return result, nil
1276+
return result, statedb, nil
1277+
}
1278+
1279+
// GetDiffAccountsWithScope returns detailed changes of some interested accounts in a specific block number.
1280+
func (s *PublicBlockChainAPI) GetDiffAccountsWithScope(ctx context.Context, blockNr rpc.BlockNumber, accounts []common.Address) (*types.DiffAccountsInBlock, error) {
1281+
if s.b.Chain() == nil {
1282+
return nil, fmt.Errorf("blockchain not support get diff accounts")
1283+
}
1284+
1285+
block, err := s.b.BlockByNumber(ctx, blockNr)
1286+
if err != nil {
1287+
return nil, fmt.Errorf("block not found for block number (%d): %v", blockNr, err)
1288+
}
1289+
1290+
needReplay, err := s.needToReplay(ctx, block, accounts)
1291+
if err != nil {
1292+
return nil, err
1293+
}
1294+
if !needReplay {
1295+
return &types.DiffAccountsInBlock{
1296+
Number: uint64(blockNr),
1297+
BlockHash: block.Hash(),
1298+
Transactions: make([]types.DiffAccountsInTx, 0),
1299+
}, nil
1300+
}
1301+
1302+
result, _, err := s.replay(ctx, block, accounts)
1303+
return result, err
12791304
}
12801305

12811306
// ExecutionResult groups all structured logs emitted by the EVM

params/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ var (
250250
RamanujanBlock: big.NewInt(0),
251251
NielsBlock: big.NewInt(0),
252252
MirrorSyncBlock: big.NewInt(5184000),
253-
BrunoBlock: nil,
253+
BrunoBlock: big.NewInt(13082000),
254254
Parlia: &ParliaConfig{
255255
Period: 3,
256256
Epoch: 200,

params/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
const (
2424
VersionMajor = 1 // Major version component of the current release
2525
VersionMinor = 1 // Minor version component of the current release
26-
VersionPatch = 4 // Patch version component of the current release
26+
VersionPatch = 5 // Patch version component of the current release
2727
VersionMeta = "" // Version metadata to append to the version string
2828
)
2929

0 commit comments

Comments
 (0)