Skip to content

Commit

Permalink
Added Hardfork history field to ChainInfo rpc.
Browse files Browse the repository at this point in the history
  • Loading branch information
hayarobi committed Nov 4, 2024
1 parent b3380d4 commit f8cd2c4
Show file tree
Hide file tree
Showing 23 changed files with 1,120 additions and 2,662 deletions.
2 changes: 1 addition & 1 deletion aergo-protobuf
19 changes: 17 additions & 2 deletions chain/chaindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,27 @@ func (cdb *ChainDB) Hardfork(hConfig config.HardforkConfig) config.HardforkDbCon
if err := json.Unmarshal(data, &c); err != nil {
return nil
}
// When a new hardkfork height is added, the hardfork config from DB (HardforkDBConfig)
// When a new hardfork height is added, the hardfork config from DB (HardforkDBConfig)
// must be modified by using the height from HardforkConfig. Without this, aergosvr fails
// to start, since a harfork heght value not stored on DB is evaluated as 0.
// to start, since a hardfork height value not stored on DB is evaluated as 0.
return c.FixDbConfig(hConfig)
}

func (cdb *ChainDB) hardforkHeights() config.HardforkDbConfig {
var c config.HardforkDbConfig
data := cdb.store.Get(dbkey.HardFork())
if len(data) == 0 {
return c
}
// TODO Hardfork status is not changed during the lifetime of server process.
// We can optimize this
if err := json.Unmarshal(data, &c); err != nil {
logger.Error().Msg("Failed to read hardfork from cdb")
return nil
}
return c
}

func (cdb *ChainDB) WriteHardfork(c *config.HardforkConfig) error {
data, err := json.Marshal(c)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions chain/chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,3 +987,7 @@ func (cs *ChainService) ChainID(bno types.BlockNo) *types.ChainID {
cid.Version = cs.cfg.Hardfork.Version(bno)
return cid
}

func (cs *ChainService) HardforkHeights() map[string]types.BlockNo {
return cs.cdb.hardforkHeights()
}
5 changes: 5 additions & 0 deletions chain/stubchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ func (tchain *StubBlockChain) ChainID(bno types.BlockNo) *types.ChainID {
return nil
}

func (tchain *StubBlockChain) HardforkHeights() map[string]types.BlockNo {
// FIXME: maybe it should return at least latest hardfork
return nil
}

func (tchain *StubBlockChain) Rollback(ancestor *types.BlockInfo) {
prevBest := tchain.Best
tchain.Best = int(ancestor.No)
Expand Down
16 changes: 15 additions & 1 deletion p2p/p2pmock/mock_chainaccessor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions p2p/p2pmock/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mockgen -source=p2p/p2pcommon/pool.go -mock_names=WaitingPeerManager=MockWaiting


# Manually generated mock classes
The generate decriptions of these mock objects are in p2p/p2pcommon/temptypes.go . So you can use such like `go generate ./p2p/p2pcommon/temptypes.go` command.
The generate descriptions of these mock objects are in p2p/p2pcommon/temptypes.go . So you can use such like `go generate ./p2p/p2pcommon/temptypes.go` command.

# mock files which are not generated automatically by go generate ./p2p
mockgen github.com/aergoio/aergo/v2/consensus ConsensusAccessor,AergoRaftAccessor | gsed -e 's/^package mock_[a-zA-Z0-9_]\+/package p2pmock/g' > p2p/p2pmock/mock_consensus.go
Expand All @@ -26,4 +26,4 @@ mockgen -source=types/blockchain.go -package=p2pmock -destination=p2p/p2pmock/mo

mockgen io Reader,ReadCloser,Writer,WriteCloser,ReadWriteCloser > p2p/p2pmock/mock_io.go | gsed -e 's/^package mock_[a-zA-Z0-9_]\+/package p2pmock/g' > p2p/p2pmock/mock_io.go

mockgen github.com/aergoio/aergo/v2/types ChainAccessor | sed -e 's/^package mock_mock_[a-zA-Z0-9_]\+/package p2pmock/g' > ../p2pmock/mock_chainaccessor.go
mockgen github.com/aergoio/aergo/v2/types ChainAccessor | sed -e 's/^package mock_[a-zA-Z0-9_]\+/package p2pmock/g' > ../p2pmock/mock_chainaccessor.go
5 changes: 5 additions & 0 deletions p2p/subproto/blockhash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package subproto
import (
"bytes"
"crypto/sha256"
"fmt"
"sync"
"testing"

Expand Down Expand Up @@ -261,6 +262,10 @@ func (a *testDoubleChainAccessor) getChain() [][]byte {
}
}

func (a *testDoubleChainAccessor) GetBlockByNo(blockNo types.BlockNo) (*types.Block, error) {
return nil, fmt.Errorf("not implemented")
}

type testDoubleHashesRespFactory struct {
lastResp *types.GetHashesResponse
lastStatus types.ResultStatus
Expand Down
52 changes: 11 additions & 41 deletions types/account.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions types/admin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/admin_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f8cd2c4

Please sign in to comment.