Skip to content

Commit 12f2c51

Browse files
zhangbinzhangbin
zhangbin
authored and
zhangbin
committed
merge v0.2.5
2 parents 4f6cbac + e8f4978 commit 12f2c51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1159
-378
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For prerequisites and detailed build instructions please read the
99
[Installation Instructions](https://github.com/elastos/Elastos.ELA.SideChain.ESC/wiki/Building-Ethereum)
1010
on the wiki.
1111

12-
Building `geth` requires both a Go (version 1.16.5 or later) and a C compiler. You can install
12+
Building `geth` requires both a Go (version 1.20 or later) and a C compiler. You can install
1313
them using your favourite package manager. Once the dependencies are installed, run
1414

1515
```shell

cmd/geth/main.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ var (
183183
utils.FrozenAccount,
184184
utils.UpdateArbiterListToLayer1Flag,
185185
utils.PledgedBillContract,
186+
utils.DeveloperFeeContract,
186187
}
187188

188189
rpcFlags = []cli.Flag{
@@ -464,7 +465,12 @@ func startSpv(ctx *cli.Context, stack *node.Node) {
464465
}
465466

466467
// calculate ELA mainchain address from the genesis block hash and set the SPV monitor address accordingly
467-
log.Info(fmt.Sprintf("Genesis block hash: %v", ghash.String()))
468+
genesisU256, err := elacom.Uint256FromBytes(ghash.Bytes())
469+
if err != nil {
470+
utils.Fatalf("Blockchain not running: %v", err)
471+
}
472+
spvCfg.GenesisHash = *genesisU256
473+
log.Info(fmt.Sprintf("Genesis block hash: %v uint256 fromat:%v", ghash.String(), genesisU256.String()))
468474
if gaddr, err := calculateGenesisAddress(ghash.String()); err != nil {
469475
utils.Fatalf("Cannot calculate: %v", err)
470476
} else {

cmd/utils/flags.go

+25
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,12 @@ var (
824824
Usage: "configue pledged bill address",
825825
Value: "",
826826
}
827+
828+
DeveloperFeeContract = cli.StringSliceFlag{
829+
Name: "developer.fee.contract",
830+
Usage: "configue developer fee contract address",
831+
Value: &cli.StringSlice{},
832+
}
827833
)
828834

829835
// MakeDataDir retrieves the currently requested data directory, terminating
@@ -1165,6 +1171,19 @@ func MakePasswordList(ctx *cli.Context) []string {
11651171
return lines
11661172
}
11671173

1174+
func MakeDeveloperFeeContractAddress(ctx *cli.Context) ([]string, error) {
1175+
list := ctx.StringSlice(DeveloperFeeContract.Name)
1176+
if len(list) == 0 {
1177+
return []string{}, nil
1178+
}
1179+
for _, account := range list {
1180+
if !common.IsHexAddress(account) {
1181+
return []string{}, errors.New("error address format")
1182+
}
1183+
}
1184+
return list, nil
1185+
}
1186+
11681187
func MakeMinerCoinbaseAddress(ctx *cli.Context) string {
11691188
path := ctx.GlobalString(PbftMinerAddress.Name)
11701189
if path == "" {
@@ -1604,6 +1623,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
16041623

16051624
cfg.DynamicArbiterHeight = ctx.GlobalUint64(DynamicArbiter.Name)
16061625
cfg.PledgedBillContract = ctx.GlobalString(PledgedBillContract.Name)
1626+
listAccount, err := MakeDeveloperFeeContractAddress(ctx)
1627+
if err != nil {
1628+
log.Error("MakeDeveloperFeeContractAddress failed", "error", err)
1629+
} else {
1630+
cfg.DeveloperFeeContract = listAccount
1631+
}
16071632

16081633
cfg.FrozenAccountList = make([]string, 0)
16091634
// Override any default configs for hard coded networks.

consensus/clique/clique.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ const (
5656
var (
5757
epochLength = uint64(30000) // Default number of blocks after which to checkpoint and reset the pending votes
5858

59-
extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
60-
extraSeal = crypto.SignatureLength // Fixed number of extra-data suffix bytes reserved for signer seal
59+
extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
60+
extraSeal = crypto.SignatureLength // Fixed number of extra-data suffix bytes reserved for signer seal
6161
extraElaHeight = 8
62-
nonceAuthVote = hexutil.MustDecode("0xffffffffffffffff") // Magic nonce number to vote on adding a new signer
63-
nonceDropVote = hexutil.MustDecode("0x0000000000000000") // Magic nonce number to vote on removing a signer.
62+
nonceAuthVote = hexutil.MustDecode("0xffffffffffffffff") // Magic nonce number to vote on adding a new signer
63+
nonceDropVote = hexutil.MustDecode("0x0000000000000000") // Magic nonce number to vote on removing a signer.
6464

6565
uncleHash = types.CalcUncleHash(nil) // Always Keccak256(RLP([])) as uncles are meaningless outside of PoW.
6666

@@ -162,7 +162,6 @@ func ecrecover(header *types.Header, sigcache *lru.ARCCache) (common.Address, er
162162
}
163163
var signer common.Address
164164
copy(signer[:], crypto.Keccak256(pubkey[1:])[12:])
165-
166165
sigcache.Add(hash, signer)
167166
return signer, nil
168167
}
@@ -383,7 +382,7 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo
383382
if checkpoint != nil {
384383
hash := checkpoint.Hash()
385384
signersSize := len(checkpoint.Extra) - extraVanity - extraSeal
386-
if signersSize %common.AddressLength == extraElaHeight {
385+
if signersSize%common.AddressLength == extraElaHeight {
387386
signersSize -= extraElaHeight
388387
}
389388

@@ -425,7 +424,7 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo
425424
beforeChangeEngine := false
426425
for i := 0; i < len(headers); i++ {
427426
beforeChangeEngine = c.isBeforeChangeEngine(chain, headers[i])
428-
log.Info("snap headers","number:", headers[i].Number.Uint64(), "beforeChangeEngine", beforeChangeEngine)
427+
log.Info("snap headers", "number:", headers[i].Number.Uint64(), "beforeChangeEngine", beforeChangeEngine)
429428
if beforeChangeEngine {
430429
log.Info("get before change engine header")
431430
break
@@ -586,7 +585,7 @@ func (c *Clique) Finalize(chain consensus.ChainReader, header *types.Header, sta
586585
// No block rewards in PoA, so the state remains as is and uncles are dropped
587586
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
588587
header.UncleHash = types.CalcUncleHash(nil)
589-
log.Info("clique finalize", "height", header.Number.Uint64(), "hash", header.Hash().String())
588+
log.Info("clique finalize", "height", header.Number.Uint64(), "hash", header.Hash().String())
590589
}
591590

592591
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
@@ -615,7 +614,7 @@ func (c *Clique) isBeforeChangeEngine(chain consensus.ChainReader,
615614
if chain.Config().PBFTBlock == nil {
616615
return false
617616
}
618-
return chain.Config().PBFTBlock.Uint64() - 1 == header.Number.Uint64()
617+
return chain.Config().PBFTBlock.Uint64()-1 == header.Number.Uint64()
619618
}
620619

621620
// Seal implements consensus.Engine, attempting to create a sealed block using
@@ -696,7 +695,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c
696695
if err != nil {
697696
return err
698697
}
699-
copy(header.Extra[length - extraSeal:], sighash)
698+
copy(header.Extra[length-extraSeal:], sighash)
700699
// Wait until sealing is terminated or delay timeout.
701700
log.Trace("Waiting for slot to sign and propagate", "delay", common.PrettyDuration(delay))
702701
go func() {

consensus/pbft/network.go

+49-4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ func (p *Pbft) BroadMessage(msg elap2p.Message) {
7676
}
7777
}
7878

79+
func (p *Pbft) BroadMessageExcept(msg elap2p.Message, exceptPeer peer.PID) {
80+
peers := p.network.DumpPeersInfo()
81+
for _, peer := range peers {
82+
pid := peer.PID[:]
83+
producer := p.dispatcher.GetConsensusView().IsProducers(pid)
84+
if producer == false {
85+
continue
86+
}
87+
if peer.PID.Equal(exceptPeer) {
88+
continue
89+
}
90+
p.network.SendMessageToPeer(peer.PID, msg)
91+
}
92+
}
93+
7994
func (p *Pbft) BroadMessageToPeers(msg elap2p.Message, peers [][]byte) {
8095
for _, pbk := range peers {
8196
pid := peer.PID{}
@@ -201,7 +216,7 @@ func (p *Pbft) OnPong(id peer.PID, height uint32) {
201216
}
202217

203218
func (p *Pbft) OnBlock(id peer.PID, block *dmsg.BlockMsg) {
204-
log.Info("-----OnBlock received------")
219+
log.Info("-----PBFT OnBlock received------")
205220
b := &types.Block{}
206221

207222
err := b.DecodeRLP(rlp.NewStream(bytes.NewBuffer(block.GetData()), 0))
@@ -306,6 +321,10 @@ func (p *Pbft) OnInv(id peer.PID, blockHash elacom.Uint256) {
306321
return
307322
}
308323
hash := common.BytesToHash(blockHash.Bytes())
324+
if p.chain.GetBlockByHash(hash) != nil {
325+
return
326+
}
327+
309328
if _, ok := p.requestedBlocks[hash]; ok {
310329
return
311330
}
@@ -317,8 +336,16 @@ func (p *Pbft) OnInv(id peer.PID, blockHash elacom.Uint256) {
317336
}
318337

319338
func (p *Pbft) OnGetBlock(id peer.PID, blockHash elacom.Uint256) {
320-
if block, ok := p.blockPool.GetBlock(blockHash); ok {
321-
if b, suc := block.(*types.Block); suc {
339+
ok := false
340+
var block dpos.DBlock
341+
block, ok = p.blockPool.GetBlock(blockHash)
342+
if !ok {
343+
hash := common.BytesToHash(blockHash.Bytes())
344+
block = p.chain.GetBlockByHash(hash)
345+
ok = block != nil
346+
}
347+
if ok {
348+
if b, suc := block.(*types.Block); suc && b != nil {
322349
buffer := bytes.NewBuffer([]byte{})
323350
err := b.EncodeRLP(buffer)
324351
if err != nil {
@@ -388,7 +415,7 @@ func (p *Pbft) OnIllegalVotesReceived(id peer.PID, votes *payload.DPOSIllegalVot
388415
}
389416

390417
func (p *Pbft) OnProposalReceived(id peer.PID, proposal *payload.DPOSProposal) {
391-
log.Info("OnProposalReceived", "hash:", proposal.Hash().String())
418+
log.Info("OnProposalReceived", "hash:", proposal.Hash().String(), "from", id.String())
392419
if _, ok := p.requestedProposals[proposal.Hash()]; ok {
393420
delete(p.requestedProposals, proposal.Hash())
394421
}
@@ -692,10 +719,28 @@ func (p *Pbft) OnBlockReceived(id peer.PID, b *dmsg.BlockMsg, confirmed bool) {
692719
log.Warn("is bigger than local number")
693720
return
694721
}
722+
if p.chain.GetBlockByHash(block.Hash()) != nil {
723+
log.Error("insert chain is known block", "hash", block.Hash().String(), "number", block.NumberU64())
724+
return
725+
}
695726
if _, err := p.chain.InsertChain(blocks); err != nil {
696727
if p.OnInsertChainError != nil {
697728
p.OnInsertChainError(id, block, err)
698729
}
730+
} else {
731+
preHash, err := elacom.Uint256FromBytes(block.ParentHash().Bytes())
732+
if err != nil {
733+
log.Error("error parent block hash", "error", err, "parentHash", block.ParentHash().String())
734+
} else {
735+
p.BroadMessageExcept(msg.NewInventory(*preHash), id)
736+
}
737+
738+
blockHash, err := elacom.Uint256FromBytes(block.Hash().Bytes())
739+
if err != nil {
740+
log.Error("error block hash", "error", err, "blockHash", block.Hash().String())
741+
} else {
742+
p.BroadMessageExcept(msg.NewInventory(*blockHash), id)
743+
}
699744
}
700745
}
701746

core/chain_makers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,4 @@ func (cr *fakeChainReader) GetHeaderByNumber(number uint64) *types.Header
297297
func (cr *fakeChainReader) GetHeaderByHash(hash common.Hash) *types.Header { return nil }
298298
func (cr *fakeChainReader) GetHeader(hash common.Hash, number uint64) *types.Header { return nil }
299299
func (cr *fakeChainReader) GetBlock(hash common.Hash, number uint64) *types.Block { return nil }
300-
func (cr *fakeChainReader) IsDangerChain() bool { return false}
300+
func (cr *fakeChainReader) IsDangerChain() bool { return false }

core/headerchain.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ type HeaderChain struct {
6969
}
7070

7171
// NewHeaderChain creates a new HeaderChain structure.
72-
// getValidator should return the parent's validator
73-
// procInterrupt points to the parent's interrupt semaphore
74-
// wg points to the parent's shutdown wait group
72+
//
73+
// getValidator should return the parent's validator
74+
// procInterrupt points to the parent's interrupt semaphore
75+
// wg points to the parent's shutdown wait group
7576
func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error) {
7677
headerCache, _ := lru.New(headerCacheLimit)
7778
tdCache, _ := lru.New(tdCacheLimit)
@@ -123,6 +124,14 @@ func (hc *HeaderChain) SetDposChain(engine consensus.Engine) {
123124
hc.pbftEngine = engine
124125
}
125126

127+
func (hc *HeaderChain) GetPOAEngine() consensus.Engine {
128+
return hc.poaEngine
129+
}
130+
131+
func (hc *HeaderChain) GetDposChain() consensus.Engine {
132+
return hc.pbftEngine
133+
}
134+
126135
// GetBlockNumber retrieves the block number belonging to the given hash
127136
// from the cache or database
128137
func (hc *HeaderChain) GetBlockNumber(hash common.Hash) *uint64 {

core/state/journal.go

+22-7
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ type journalEntry interface {
3333
}
3434

3535
// journal contains the list of state modifications applied since the last state
36-
// commit. These are tracked to be able to be reverted in case of an execution
37-
// exception or revertal request.
36+
// commit. These are tracked to be able to be reverted in the case of an execution
37+
// exception or request for reversal.
3838
type journal struct {
3939
entries []journalEntry // Current changes tracked by the journal
4040
dirties map[common.Address]int // Dirty accounts and the number of changes
4141
}
4242

43-
// newJournal create a new initialized journal.
43+
// newJournal creates a new initialized journal.
4444
func newJournal() *journal {
4545
return &journal{
4646
dirties: make(map[common.Address]int),
@@ -90,7 +90,8 @@ type (
9090
account *common.Address
9191
}
9292
resetObjectChange struct {
93-
prev *stateObject
93+
prev *stateObject
94+
prevdestruct bool
9495
}
9596
suicideChange struct {
9697
account *common.Address
@@ -127,9 +128,7 @@ type (
127128
hash common.Hash
128129
}
129130
touchChange struct {
130-
account *common.Address
131-
prev bool
132-
prevDirty bool
131+
account *common.Address
133132
}
134133
// Changes to the access list
135134
accessListAddAccountChange struct {
@@ -139,6 +138,11 @@ type (
139138
address *common.Address
140139
slot *common.Hash
141140
}
141+
142+
transientStorageChange struct {
143+
account *common.Address
144+
key, prevalue common.Hash
145+
}
142146
)
143147

144148
func (ch createObjectChange) revert(s *StateDB) {
@@ -152,6 +156,9 @@ func (ch createObjectChange) dirtied() *common.Address {
152156

153157
func (ch resetObjectChange) revert(s *StateDB) {
154158
s.setStateObject(ch.prev)
159+
if !ch.prevdestruct {
160+
delete(s.stateObjectsDestruct, ch.prev.address)
161+
}
155162
}
156163

157164
func (ch resetObjectChange) dirtied() *common.Address {
@@ -211,6 +218,14 @@ func (ch storageChange) dirtied() *common.Address {
211218
return ch.account
212219
}
213220

221+
func (ch transientStorageChange) revert(s *StateDB) {
222+
s.setTransientState(*ch.account, ch.key, ch.prevalue)
223+
}
224+
225+
func (ch transientStorageChange) dirtied() *common.Address {
226+
return nil
227+
}
228+
214229
func (ch refundChange) revert(s *StateDB) {
215230
s.refund = ch.prev
216231
}

0 commit comments

Comments
 (0)