Skip to content

Commit

Permalink
Merge pull request ethereum#296 from XinFinOrg/dev-upgrade-merge-master
Browse files Browse the repository at this point in the history
Dev upgrade merge master
  • Loading branch information
liam-lai authored Aug 2, 2023
2 parents 176a3d0 + 69c38ac commit bb6d797
Show file tree
Hide file tree
Showing 30 changed files with 376 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ go.sum

cicd/devnet/terraform/.terraform
cicd/devnet/.pwd
cicd/devnet/tmp/
cicd/devnet/tmp/
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ env:

jobs:
include:
# TODO: temporary turn off linting to help fix all the tests. We will turn it back on once the branch is stable
# - stage: Lint
# sudo: false
# go: '1.14.x'
# git:
# submodules: false
# script:
# - go run build/ci.go lint

- stage: Tests
os: linux
dist: bionic
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# XDPoSChain

<p align="center">
<img src="./assets/images/xinfin-logo.png" />
</p>

<p align="center">
XinFin XDPoSchain<br/>
Enterprise ready hybrid blockchain for global trade and finance
</p>
<br/>

## XinFin Hybrid Blockchain

XinFin Hybrid Blockchain is an Enterprise ready Blockchain for global trade and finance
Expand Down Expand Up @@ -51,5 +62,4 @@ See https://github.com/XinFinOrg/XDPoSChain/tree/dev-upgrade/cicd

Simple create a pull request along with proper reasoning, we'll get back to you.

Our Channels : [Telegram Developer Group](https://t.me/XinFinDevelopers) or [Public Slack Group](https://launchpass.com/xinfin-public)

Our Channels : [Telegram Developer Group](https://t.me/XinFinDevelopers) or [XDC.Dev](https://xdc.dev)
2 changes: 1 addition & 1 deletion XDCxlending/lendingstate/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

var (
EmptyAddress = "0x0000000000000000000000000000000000000000"
EmptyAddress = "xdc0000000000000000000000000000000000000000"
EmptyRoot = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
)

Expand Down
26 changes: 26 additions & 0 deletions accounts/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ package abi
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"

"github.com/XinFinOrg/XDPoSChain/crypto"
)

// The ABI holds information about a contract's context and available
Expand Down Expand Up @@ -144,3 +147,26 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
}
return nil, fmt.Errorf("no method with id: %#x", sigdata[:4])
}


// revertSelector is a special function selector for revert reason unpacking.
var revertSelector = crypto.Keccak256([]byte("Error(string)"))[:4]

// UnpackRevert resolves the abi-encoded revert reason. According to the solidity
// spec https://solidity.readthedocs.io/en/latest/control-structures.html#revert,
// the provided revert reason is abi-encoded as if it were a call to a function
// `Error(string)`. So it's a special tool for it.
func UnpackRevert(data []byte) (string, error) {
if len(data) < 4 {
return "", errors.New("invalid data for unpacking")
}
if !bytes.Equal(data[:4], revertSelector) {
return "", errors.New("invalid data for unpacking")
}
typ, _ := NewType("string")
unpacked, err := (Arguments{{Type: typ}}).Unpack2(data[4:])
if err != nil {
return "", err
}
return unpacked[0].(string), nil
}
12 changes: 12 additions & 0 deletions accounts/abi/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package abi

import (
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -100,6 +101,17 @@ func (arguments Arguments) Unpack(v interface{}, data []byte) error {
return arguments.unpackAtomic(v, marshalledValues)
}

// Unpack2 performs the operation hexdata -> Go format.
func (arguments Arguments) Unpack2(data []byte) ([]interface{}, error) {
if len(data) == 0 {
if len(arguments.NonIndexed()) != 0 {
return nil, errors.New("abi: attempting to unmarshall an empty string while arguments are expected")
}
return make([]interface{}, 0), nil
}
return arguments.UnpackValues(data)
}

func (arguments Arguments) unpackTuple(v interface{}, marshalledValues []interface{}) error {

var (
Expand Down
5 changes: 3 additions & 2 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call XDPoSChain.Call

// callContract implements common code between normal and pending contract calls.
// state is modified during execution, make sure to copy it if necessary.
func (b *SimulatedBackend) callContract(ctx context.Context, call XDPoSChain.CallMsg, block *types.Block, statedb *state.StateDB) ([]byte, uint64, bool, error) {
func (b *SimulatedBackend) callContract(ctx context.Context, call XDPoSChain.CallMsg, block *types.Block, statedb *state.StateDB) (ret []byte, usedGas uint64, failed bool, err error) {
// Ensure message is initialized properly.
if call.GasPrice == nil {
call.GasPrice = big.NewInt(1)
Expand Down Expand Up @@ -379,7 +379,8 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call XDPoSChain.Cal
vmenv := vm.NewEVM(evmContext, statedb, nil, b.config, vm.Config{})
gaspool := new(core.GasPool).AddGas(math.MaxUint64)
owner := common.Address{}
return core.NewStateTransition(vmenv, msg, gaspool).TransitionDb(owner)
ret, usedGas, failed, err, _ = core.NewStateTransition(vmenv, msg, gaspool).TransitionDb(owner)
return
}

// SendTransaction updates the pending block to include the given transaction.
Expand Down
Binary file added assets/images/xinfin-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 143 additions & 0 deletions cmd/XDC/apothem.go

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions cmd/XDC/bugcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,4 @@ const header = `Please answer these questions before submitting your issue. Than
#### What did you see instead?
#### System details
`
#### System details`
40 changes: 26 additions & 14 deletions cmd/XDC/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ import (
"sync/atomic"
"time"

"github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/metrics"

"github.com/XinFinOrg/XDPoSChain/cmd/utils"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/console"
"github.com/XinFinOrg/XDPoSChain/core"
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/state"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
"github.com/XinFinOrg/XDPoSChain/event"
"github.com/XinFinOrg/XDPoSChain/log"
"github.com/XinFinOrg/XDPoSChain/metrics"
"gopkg.in/urfave/cli.v1"
)

Expand All @@ -49,6 +48,7 @@ var (
Flags: []cli.Flag{
utils.DataDirFlag,
utils.LightModeFlag,
utils.XDCTestnetFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
Expand Down Expand Up @@ -176,19 +176,31 @@ Use "ethereum dump 0" to dump the genesis block.`,
func initGenesis(ctx *cli.Context) error {
// Make sure we have a valid genesis JSON
genesisPath := ctx.Args().First()
if len(genesisPath) == 0 {
utils.Fatalf("Must supply path to genesis JSON file")
}
file, err := os.Open(genesisPath)
if err != nil {
utils.Fatalf("Failed to read genesis file: %v", err)
}
defer file.Close()

genesis := new(core.Genesis)
if err := json.NewDecoder(file).Decode(genesis); err != nil {
utils.Fatalf("invalid genesis file: %v", err)

if ctx.GlobalBool(utils.XDCTestnetFlag.Name) {
if len(genesisPath) > 0 {
utils.Fatalf("Flags --apothem and genesis file can't be used at the same time")
}
err := json.Unmarshal(apothemGenesis, &genesis)
if err != nil {
utils.Fatalf("invalid genesis json: %v", err)
}
} else {
if len(genesisPath) == 0 {
utils.Fatalf("Must supply path to genesis JSON file")
}
file, err := os.Open(genesisPath)
if err != nil {
utils.Fatalf("Failed to read genesis file: %v", err)
}
defer file.Close()

if err := json.NewDecoder(file).Decode(genesis); err != nil {
utils.Fatalf("invalid genesis file: %v", err)
}
}

// Open an initialise both full and light databases
stack, _ := makeFullNode(ctx)
for _, name := range []string{"chaindata", "lightchaindata"} {
Expand Down
5 changes: 4 additions & 1 deletion cmd/XDC/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,14 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) {
common.TRC21IssuerSMC = common.TRC21IssuerSMCTestNet
cfg.Eth.NetworkId = 51
common.RelayerRegistrationSMC = common.RelayerRegistrationSMCTestnet
common.TIPTRC21Fee = common.TIPXDCXTestnet
common.TIPTRC21Fee = common.TIPTRC21FeeTestnet
common.TIPXDCXCancellationFee = common.TIPXDCXCancellationFeeTestnet
}

if ctx.GlobalBool(utils.Enable0xPrefixFlag.Name) {
common.Enable0xPrefix = true
}

// Rewound
if rewound := ctx.GlobalInt(utils.RewoundFlag.Name); rewound != 0 {
common.Rewound = uint64(rewound)
Expand Down
1 change: 1 addition & 0 deletions cmd/XDC/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ var (
//utils.RinkebyFlag,
//utils.VMEnableDebugFlag,
utils.XDCTestnetFlag,
utils.Enable0xPrefixFlag,
utils.RewoundFlag,
utils.NetworkIdFlag,
utils.RPCCORSDomainFlag,
Expand Down
4 changes: 4 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ var (
Usage: "Rollback chain at hash",
Value: "",
}
Enable0xPrefixFlag = cli.BoolFlag{
Name: "enable-0x-prefix",
Usage: "Addres use 0x-prefix (default = false)",
}
// General settings
AnnounceTxsFlag = cli.BoolFlag{
Name: "announce-txs",
Expand Down
1 change: 1 addition & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var TIPXDCXCancellationFeeTestnet = big.NewInt(38383838)

var TIPXDCXTestnet = big.NewInt(38383838)
var IsTestnet bool = false
var Enable0xPrefix bool = false
var StoreRewardFolder string
var RollbackHash Hash
var BasePrice = big.NewInt(1000000000000000000) // 1
Expand Down
7 changes: 5 additions & 2 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,11 @@ func (a *Address) Set(other Address) {
// MarshalText returns the hex representation of a.
func (a Address) MarshalText() ([]byte, error) {
// Handle '0x' or 'xdc' prefix here.
// return hexutil.Bytes(a[:]).MarshalText()
return hexutil.Bytes(a[:]).MarshalXDCText()
if (Enable0xPrefix) {
return hexutil.Bytes(a[:]).MarshalText()
} else {
return hexutil.Bytes(a[:]).MarshalXDCText()
}
}

// UnmarshalText parses a hash in hex syntax.
Expand Down
2 changes: 1 addition & 1 deletion consensus/XDPoS/engines/engine_v2/epochSwitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (x *XDPoS_v2) getEpochSwitchInfo(chain consensus.ChainReader, header *types
return nil, err
}

snap, err := x.getSnapshot(chain, header.Number.Uint64(), false)
snap, err := x.getSnapshot(chain, h.Number.Uint64(), false)
if err != nil {
log.Error("[getEpochSwitchInfo] Adaptor v2 getSnapshot has error", "err", err)
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions consensus/tests/engine_v2_tests/adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func TestAdaptorGetMasternodesV2(t *testing.T) {

// block 901 is the first v2 block, and is treated as epoch switch block
err := blockchain.InsertBlock(currentBlock)
adaptor.Initial(blockchain, currentBlock.Header())
assert.Nil(t, err)
masternodes1 := adaptor.GetMasternodes(blockchain, currentBlock.Header())
assert.Equal(t, 5, len(masternodes1))
Expand Down Expand Up @@ -216,6 +217,8 @@ func TestGetCurrentEpochSwitchBlock(t *testing.T) {
currentBlock = CreateBlock(blockchain, params.TestXDPoSMockChainConfig, currentBlock, blockNum, 1, blockCoinBase, signer, signFn, nil, nil, "")
err = blockchain.InsertBlock(currentBlock)
assert.Nil(t, err)
adaptor.Initial(blockchain, currentBlock.Header())

currentCheckpointNumber, epochNum, err = adaptor.GetCurrentEpochSwitchBlock(blockchain, currentBlock.Number())
assert.Nil(t, err)
assert.Equal(t, uint64(901), currentCheckpointNumber)
Expand Down
2 changes: 2 additions & 0 deletions consensus/tests/engine_v2_tests/authorised_masternode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func TestIsYourTurnConsensusV2(t *testing.T) {
currentBlockHeader.Time = big.NewInt(time.Now().Unix())
err := blockchain.InsertBlock(currentBlock)
assert.Nil(t, err)
adaptor.Initial(blockchain, currentBlockHeader)

// Less then Mine Period
isYourTurn, err := adaptor.YourTurn(blockchain, currentBlockHeader, common.HexToAddress("xdc0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e"))
assert.Nil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func ApplyTransaction(config *params.ChainConfig, tokensFee map[common.Address]*
// End Bypass blacklist address

// Apply the transaction to the current state (included in the env)
_, gas, failed, err := ApplyMessage(vmenv, msg, gp, coinbaseOwner)
_, gas, failed, err, _ := ApplyMessage(vmenv, msg, gp, coinbaseOwner)

if err != nil {
return nil, 0, err, false
Expand Down
12 changes: 6 additions & 6 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
// the gas used (which includes gas refunds) and an error if it failed. An error always
// indicates a core error meaning that the message would always fail for that particular
// state and would never be accepted within a block.
func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool, owner common.Address) ([]byte, uint64, bool, error) {
func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool, owner common.Address) ([]byte, uint64, bool, error, error) {
return NewStateTransition(evm, msg, gp).TransitionDb(owner)
}

Expand Down Expand Up @@ -215,7 +215,7 @@ func (st *StateTransition) preCheck() error {
// TransitionDb will transition the state by applying the current message and
// returning the result including the the used gas. It returns an error if it
// failed. An error indicates a consensus issue.
func (st *StateTransition) TransitionDb(owner common.Address) (ret []byte, usedGas uint64, failed bool, err error) {
func (st *StateTransition) TransitionDb(owner common.Address) (ret []byte, usedGas uint64, failed bool, err error, vmErr error) {
if err = st.preCheck(); err != nil {
return
}
Expand All @@ -228,10 +228,10 @@ func (st *StateTransition) TransitionDb(owner common.Address) (ret []byte, usedG
// Pay intrinsic gas
gas, err := IntrinsicGas(st.data, contractCreation, homestead)
if err != nil {
return nil, 0, false, err
return nil, 0, false, err, nil
}
if err = st.useGas(gas); err != nil {
return nil, 0, false, err
return nil, 0, false, err, nil
}

var (
Expand Down Expand Up @@ -261,7 +261,7 @@ func (st *StateTransition) TransitionDb(owner common.Address) (ret []byte, usedG
// sufficient balance to make the transfer happen. The first
// balance transfer may never fail.
if vmerr == vm.ErrInsufficientBalance {
return nil, 0, false, vmerr
return nil, 0, false, vmerr, nil
}
}
st.refundGas()
Expand All @@ -274,7 +274,7 @@ func (st *StateTransition) TransitionDb(owner common.Address) (ret []byte, usedG
st.state.AddBalance(st.evm.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.gasPrice))
}

return ret, st.gasUsed(), vmerr != nil, err
return ret, st.gasUsed(), vmerr != nil, err, vmerr
}

func (st *StateTransition) refundGas() {
Expand Down
2 changes: 1 addition & 1 deletion core/token_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func CallContractWithState(call ethereum.CallMsg, chain consensus.ChainContext,
vmenv := vm.NewEVM(evmContext, statedb, nil, chain.Config(), vm.Config{})
gaspool := new(GasPool).AddGas(1000000)
owner := common.Address{}
rval, _, _, err := NewStateTransition(vmenv, msg, gaspool).TransitionDb(owner)
rval, _, _, err, _ := NewStateTransition(vmenv, msg, gaspool).TransitionDb(owner)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,5 @@ func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data }
func (m Message) CheckNonce() bool { return m.checkNonce }

func (m *Message) SetNonce(nonce uint64) { m.nonce = nonce }
Loading

0 comments on commit bb6d797

Please sign in to comment.