Skip to content

Commit

Permalink
Merge pull request #99 from kaiachain/release/v1.0.3
Browse files Browse the repository at this point in the history
[Main] release/v1.0.3 QA Sign-off
  • Loading branch information
blukat29 authored Sep 26, 2024
2 parents 9f03292 + 74d7f51 commit f329a68
Show file tree
Hide file tree
Showing 37 changed files with 1,406 additions and 392 deletions.
338 changes: 149 additions & 189 deletions .circleci/config.yml

Large diffs are not rendered by default.

24 changes: 1 addition & 23 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
#* @global-owner1 @global-owner2
* @aidan-kwon @blukat29 @yoomee1313
* @aidan-kwon @blukat29 @yoomee1313 @ian0371

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
Expand Down Expand Up @@ -37,25 +37,3 @@
# directory in the root of your repository.
#/docs/ @doctocat

/.circleci/ @yoomee1313 @JayChoi1736 @2dvorak @sjnam
/.github/ @yoomee1313 @JayChoi1736 @2dvorak @sjnam
/accounts/ @blukat29 @hyunsooda @2dvorak @kjeom @JayChoi1736
/api/ @blukat29 @hyunsooda @2dvorak @kjeom @JayChoi1736
/blockchain/ @yoomee1313 @sjnam @ian0371 @hyeonLewis
/build/ @yoomee1313 @JayChoi1736 @2dvorak @sjnam
/client/ @blukat29 @hyunsooda @2dvorak @kjeom @JayChoi1736
/cmd/ @blukat29 @hyunsooda @2dvorak @kjeom @JayChoi1736
/consensus/ @blukat29 @ian0371 @hyeonLewis
/console/ @blukat29 @hyunsooda @2dvorak @kjeom @JayChoi1736
/contracts/ @blukat29 @ian0371 @hyeonLewis
/crypto/ @blukat29 @ian0371 @hyeonLewis
/datasync/ @aidan-kwon @blukat29 @jeongkyun-oh
/db_migration/ @aidan-kwon @blukat29 @jeongkyun-oh
/governance/ @blukat29 @ian0371 @hyeonLewis
/networks/ @yoomee1313 @JayChoi1736 @2dvorak @sjnam
/node/ @blukat29 @hyunsooda @2dvorak @kjeom @JayChoi1736
/params/ @yoomee1313 @sjnam @ian0371 @hyeonLewis
/reward/ @blukat29 @ian0371 @hyeonLewis
/snapshot/ @aidan-kwon @blukat29 @jeongkyun-oh
/storage/ @aidan-kwon @blukat29 @jeongkyun-oh
/work/ @yoomee1313 @sjnam @ian0371 @hyeonLewis
11 changes: 7 additions & 4 deletions api/api_ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func (api *EthereumAPI) Call(ctx context.Context, args EthTransactionArgs, block

// EstimateGas returns an estimate of the amount of gas needed to execute the
// given transaction against the current pending block.
func (api *EthereumAPI) EstimateGas(ctx context.Context, args EthTransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) {
func (api *EthereumAPI) EstimateGas(ctx context.Context, args EthTransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *EthStateOverride) (hexutil.Uint64, error) {
bcAPI := api.publicBlockChainAPI.b
bNrOrHash := rpc.NewBlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
if blockNrOrHash != nil {
Expand All @@ -703,7 +703,7 @@ func (api *EthereumAPI) EstimateGas(ctx context.Context, args EthTransactionArgs
if rpcGasCap := bcAPI.RPCGasCap(); rpcGasCap != nil {
gasCap = rpcGasCap.Uint64()
}
return EthDoEstimateGas(ctx, bcAPI, args, bNrOrHash, gasCap)
return EthDoEstimateGas(ctx, bcAPI, args, bNrOrHash, overrides, gasCap)
}

// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
Expand Down Expand Up @@ -1434,7 +1434,7 @@ func EthDoCall(ctx context.Context, b Backend, args EthTransactionArgs, blockNrO
return result, nil
}

func EthDoEstimateGas(ctx context.Context, b Backend, args EthTransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (hexutil.Uint64, error) {
func EthDoEstimateGas(ctx context.Context, b Backend, args EthTransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *EthStateOverride, gasCap uint64) (hexutil.Uint64, error) {
// Use zero address if sender unspecified.
if args.From == nil {
args.From = new(common.Address)
Expand All @@ -1459,11 +1459,14 @@ func EthDoEstimateGas(ctx context.Context, b Backend, args EthTransactionArgs, b
if err != nil {
return 0, err
}
if err := overrides.Apply(state); err != nil {
return 0, err
}
balance := state.GetBalance(*args.From) // from can't be nil

executable := func(gas uint64) (bool, *blockchain.ExecutionResult, error) {
args.Gas = (*hexutil.Uint64)(&gas)
result, err := EthDoCall(ctx, b, args, rpc.NewBlockNumberOrHashWithNumber(rpc.LatestBlockNumber), nil, b.RPCEVMTimeout(), gasCap)
result, err := EthDoCall(ctx, b, args, blockNrOrHash, overrides, b.RPCEVMTimeout(), gasCap)
if err != nil {
if errors.Is(err, blockchain.ErrIntrinsicGas) {
return true, nil, nil // Special case, raise gas limit
Expand Down
2 changes: 1 addition & 1 deletion api/api_ethereum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2600,6 +2600,6 @@ func TestEthereumAPI_EstimateGas(t *testing.T) {
defer mockCtrl.Finish()

testEstimateGas(t, mockBackend, func(args EthTransactionArgs) (hexutil.Uint64, error) {
return api.EstimateGas(context.Background(), args, nil)
return api.EstimateGas(context.Background(), args, nil, nil)
})
}
17 changes: 12 additions & 5 deletions api/api_public_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,32 +400,39 @@ func (s *PublicBlockChainAPI) EstimateComputationCost(ctx context.Context, args
}

// EstimateGas returns an estimate of the amount of gas needed to execute the given transaction against the latest block.
func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs) (hexutil.Uint64, error) {
func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *EthStateOverride) (hexutil.Uint64, error) {
gasCap := uint64(0)
if rpcGasCap := s.b.RPCGasCap(); rpcGasCap != nil {
gasCap = rpcGasCap.Uint64()
}
return DoEstimateGas(ctx, s.b, args, s.b.RPCEVMTimeout(), new(big.Int).SetUint64(gasCap))
bNrOrHash := rpc.NewBlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
if blockNrOrHash != nil {
bNrOrHash = *blockNrOrHash
}
return DoEstimateGas(ctx, s.b, args, bNrOrHash, overrides, s.b.RPCEVMTimeout(), new(big.Int).SetUint64(gasCap))
}

func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, timeout time.Duration, gasCap *big.Int) (hexutil.Uint64, error) {
func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *EthStateOverride, timeout time.Duration, gasCap *big.Int) (hexutil.Uint64, error) {
var feeCap *big.Int
if args.GasPrice != nil {
feeCap = args.GasPrice.ToInt()
} else {
feeCap = common.Big0
}

state, _, err := b.StateAndHeaderByNumber(ctx, rpc.LatestBlockNumber)
state, _, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
if err != nil {
return 0, err
}
if err := overrides.Apply(state); err != nil {
return 0, err
}
balance := state.GetBalance(args.From) // from can't be nil

// Create a helper to check if a gas allowance results in an executable transaction
executable := func(gas uint64) (bool, *blockchain.ExecutionResult, error) {
args.Gas = hexutil.Uint64(gas)
result, _, err := DoCall(ctx, b, args, rpc.NewBlockNumberOrHashWithNumber(rpc.LatestBlockNumber), vm.Config{ComputationCostLimit: params.OpcodeComputationCostLimitInfinite}, timeout, gasCap)
result, _, err := DoCall(ctx, b, args, blockNrOrHash, vm.Config{ComputationCostLimit: params.OpcodeComputationCostLimitInfinite}, timeout, gasCap)
if err != nil {
if errors.Is(err, blockchain.ErrIntrinsicGas) {
return true, nil, nil // Special case, raise gas limit
Expand Down
2 changes: 1 addition & 1 deletion api/api_public_blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ func TestKaiaAPI_EstimateGas(t *testing.T) {
if ethArgs.Value != nil {
args.Value = *ethArgs.Value
}
return api.EstimateGas(context.Background(), args)
return api.EstimateGas(context.Background(), args, nil, nil)
})
}
2 changes: 1 addition & 1 deletion api/tx_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ func (args *EthTransactionArgs) setDefaults(ctx context.Context, b Backend) erro
if rpcGasCap := b.RPCGasCap(); rpcGasCap != nil {
gasCap = rpcGasCap.Uint64()
}
estimated, err := EthDoEstimateGas(ctx, b, callArgs, pendingBlockNr, gasCap)
estimated, err := EthDoEstimateGas(ctx, b, callArgs, pendingBlockNr, nil, gasCap)
if err != nil {
return err
}
Expand Down
8 changes: 5 additions & 3 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ type BlockChain struct {
currentBlock atomic.Value // Current head of the block chain
currentFastBlock atomic.Value // Current head of the fast-sync chain (may be above the block chain!)

stateCache state.Database // State database to reuse between imports (contains state cache)
futureBlocks *lru.Cache // future blocks are blocks added for later processing
stateCache state.Database // State database to reuse between imports (contains state cache)

// future blocks are blocks added for later processing
futureBlocks *lru.Cache

quit chan struct{} // blockchain quit channel
running int32 // running must be called atomically
Expand Down Expand Up @@ -1088,8 +1090,8 @@ func (bc *BlockChain) Stop() {
if snapBase, err = bc.snaps.Journal(bc.CurrentBlock().Root()); err != nil {
logger.Error("Failed to journal state snapshot", "err", err)
}
bc.snaps.Release()
}

triedb := bc.stateCache.TrieDB()
if !bc.isArchiveMode() {
number := bc.CurrentBlock().NumberU64()
Expand Down
18 changes: 9 additions & 9 deletions blockchain/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"errors"
"fmt"

"github.com/VictoriaMetrics/fastcache"
"github.com/kaiachain/kaia/common"
"github.com/kaiachain/kaia/common/lru"
"github.com/kaiachain/kaia/storage/database"
"github.com/kaiachain/kaia/storage/statedb"
)
Expand Down Expand Up @@ -144,7 +144,7 @@ func NewDatabaseWithNewCache(db database.DBManager, cacheConfig *statedb.TrieNod
return &cachingDB{
db: statedb.NewDatabaseWithNewCache(db, cacheConfig),
codeSizeCache: getCodeSizeCache(),
codeCache: fastcache.New(codeCacheSize),
codeCache: lru.NewSizeConstrainedCache[common.Hash, []byte](codeCacheSize),
}
}

Expand All @@ -155,14 +155,14 @@ func NewDatabaseWithExistingCache(db database.DBManager, cache statedb.TrieNodeC
return &cachingDB{
db: statedb.NewDatabaseWithExistingCache(db, cache),
codeSizeCache: getCodeSizeCache(),
codeCache: fastcache.New(codeCacheSize),
codeCache: lru.NewSizeConstrainedCache[common.Hash, []byte](codeCacheSize),
}
}

type cachingDB struct {
db *statedb.Database
codeSizeCache common.Cache
codeCache *fastcache.Cache
codeCache *lru.SizeConstrainedCache[common.Hash, []byte]
}

// OpenTrie opens the main account trie at a specific root hash.
Expand All @@ -187,12 +187,12 @@ func (db *cachingDB) CopyTrie(t Trie) Trie {

// ContractCode retrieves a particular contract's code.
func (db *cachingDB) ContractCode(codeHash common.Hash) ([]byte, error) {
if code := db.codeCache.Get(nil, codeHash.Bytes()); len(code) > 0 {
if code, _ := db.codeCache.Get(codeHash); len(code) > 0 {
return code, nil
}
code := db.db.DiskDB().ReadCode(codeHash)
if len(code) > 0 {
db.codeCache.Set(codeHash.Bytes(), code)
db.codeCache.Add(codeHash, code)
db.codeSizeCache.Add(codeHash, len(code))
return code, nil
}
Expand All @@ -201,20 +201,20 @@ func (db *cachingDB) ContractCode(codeHash common.Hash) ([]byte, error) {

// DeleteCode deletes a particular contract's code.
func (db *cachingDB) DeleteCode(codeHash common.Hash) {
db.codeCache.Del(codeHash.Bytes())
db.codeCache.DeleteCode(codeHash)
db.db.DiskDB().DeleteCode(codeHash)
}

// ContractCodeWithPrefix retrieves a particular contract's code. If the
// code can't be found in the cache, then check the existence with **new**
// db scheme.
func (db *cachingDB) ContractCodeWithPrefix(codeHash common.Hash) ([]byte, error) {
if code := db.codeCache.Get(nil, codeHash.Bytes()); len(code) > 0 {
if code, _ := db.codeCache.Get(codeHash); len(code) > 0 {
return code, nil
}
code := db.db.DiskDB().ReadCodeWithPrefix(codeHash)
if len(code) > 0 {
db.codeCache.Set(codeHash.Bytes(), code)
db.codeCache.Add(codeHash, code)
db.codeSizeCache.Add(codeHash, len(code))
return code, nil
}
Expand Down
3 changes: 3 additions & 0 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ func buildFlags(env build.Environment) (flags []string) {
// Pass the static link flag to the external linker.
// By default, cmd/link will use external linking mode when non-standard cgo packages are involved.
ld = append(ld, "-linkmode", "external", "-extldflags", "-static")
// Even if the binary is statically linked, some glibc features (e.g., libnss) can have dependencies on
// specific version of glibc. So we should try to avoid using them.
flags = append(flags, "-tags", "osusergo,netgo")
}
if env.IsKaiaRaceDetectionOn {
flags = append(flags, "-race")
Expand Down
19 changes: 9 additions & 10 deletions build/package-tar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -e
function printUsage {
echo "Usage: ${0} [-b] <arch> <target>"
echo " -b: use Kairos configuration"
echo " <arch>: linux-386 | linux-amd64 | darwin-arm64 | windows-386 | windows-amd64"
echo " <arch>: linux-386 | linux-amd64 | linux-arm64 | darwin-arm64"
echo " <target>: kcn | kpn | ken | kbn | kscn | kspn | ksen | kgen | homi"
echo ""
echo " ${0} linux-amd64 kcn"
Expand Down Expand Up @@ -39,20 +39,16 @@ case "$SUBCOMMAND" in
PLATFORM_SUFFIX="linux-amd64"
shift
;;
darwin-arm64)
PLATFORM_SUFFIX="darwin-arm64"
shift
;;
windows-386)
PLATFORM_SUFFIX="windows-386"
linux-arm64)
PLATFORM_SUFFIX="linux-arm64"
shift
;;
windows-amd64)
PLATFORM_SUFFIX="windows-amd64"
darwin-arm64)
PLATFORM_SUFFIX="darwin-arm64"
shift
;;
*)
echo "Undefined architecture for packaging. Supported architectures: linux-386, linux-amd64, darwin-arm64, windows-386, windows-amd64"
echo "Undefined architecture for packaging. Supported architectures: linux-386, linux-amd64, linux-arm64, darwin-arm64"
printUsage
;;
esac
Expand Down Expand Up @@ -127,3 +123,6 @@ fi
# Compress!
mkdir -p packages
tar czf packages/$KAIA_PACKAGE_NAME $PACK_NAME

# Clean-up code except the packages folder
rm -rf ${PACK_NAME}
Loading

0 comments on commit f329a68

Please sign in to comment.