Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ab2913d
replace stakeview with voteview
envestcc Sep 27, 2025
d32eb3f
fix test
envestcc Sep 28, 2025
3441c5e
refactor view
CoderZhi Sep 29, 2025
5aaeb3c
address comment
CoderZhi Sep 29, 2025
4074aec
add unit test and fix a log error
CoderZhi Sep 29, 2025
62d0b2b
fix build
envestcc Sep 17, 2025
f1cdac6
add migrate unit test
CoderZhi Sep 30, 2025
b437ec1
store candidate votes in erigondb
envestcc Sep 28, 2025
c7cf13e
update matchContractIndex and move registrations into erigonstore
CoderZhi Sep 28, 2025
59a582a
store contract buckets in erigondb
envestcc Sep 28, 2025
eea60f4
fix wrapper base
envestcc Sep 30, 2025
51cf3b1
fix system contract index
envestcc Sep 30, 2025
920a22b
introduce xingu hardfork
envestcc Sep 30, 2025
9376b20
fix staking
envestcc Sep 30, 2025
0d3b2ad
fix pack staking event error
envestcc Oct 10, 2025
f5dcc6c
add candidate register/update test
envestcc Oct 10, 2025
c8b5cfe
fix slash not apply
envestcc Oct 10, 2025
68596fd
address comment
CoderZhi Oct 2, 2025
02bb24d
slash candidate by operator
envestcc Oct 15, 2025
7255b34
update election
envestcc Oct 14, 2025
062a00c
xingubeta hardfork
envestcc Oct 15, 2025
9113273
fix erigon state not exist
envestcc Oct 16, 2025
1aa9f0c
fix test
envestcc Oct 16, 2025
5a8430d
v4 to read candidate
CoderZhi Oct 13, 2025
0a338bd
fix blskey not copied
envestcc Oct 16, 2025
c39ed2e
fix blskey before xingubeta
envestcc Oct 17, 2025
fb07c78
fix start ctx
envestcc Oct 17, 2025
cd3c3ed
slash candidate unit test
CoderZhi Sep 10, 2025
737d334
credit bucket pool without deleting bucket
CoderZhi Sep 30, 2025
6e80054
address comment
CoderZhi Oct 2, 2025
7cae877
unit test for nft event handler
CoderZhi Sep 18, 2025
8a84575
fix test
envestcc Sep 30, 2025
7759839
fix viewdata panic
envestcc Oct 20, 2025
3fb8b3f
fix panic
envestcc Oct 21, 2025
69da239
fix conflict
envestcc Oct 21, 2025
5e7fe38
log start
envestcc Oct 9, 2025
5a51d63
Fix candidate votes serialization order
envestcc Oct 21, 2025
4a695d4
Update Xingu and XinguBeta block heights
envestcc Oct 21, 2025
ae055d0
Merge branch 'master' into fixxingu
envestcc Oct 21, 2025
78f1a03
Merge branch 'master' into fixxingu
CoderZhi Oct 24, 2025
29ee367
update ci
CoderZhi Oct 24, 2025
191c10c
update go.test.sh
CoderZhi Oct 25, 2025
dc07845
update ci
CoderZhi Oct 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,20 @@ env:
jobs:
ci:
name: ci flow
runs-on: self-hosted
container:
image: ubuntu:latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# with:
# submodules: recursive

- name: Install build tools
run: |
apt-get update
apt-get install -y build-essential ca-certificates
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.23.0
cache: false

- name: Build Go
run: CGO_ENABLED=1 go build ./...
run: go build ./...

- name: Run Test
id: unittest
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ recover:

.PHONY: ioctl
ioctl:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_IOCTL) -v ./tools/ioctl
$(GOBUILD) -tags $(BUILD_TAGS) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_IOCTL) -v ./tools/ioctl

.PHONY: newioctl
newioctl:
Expand Down
14 changes: 7 additions & 7 deletions action/candidate_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,18 @@ func PackCandidateRegisteredEvent(
blsPubKey []byte,
) (Topics, []byte, error) {
data, err := _candidateRegisteredEvent.Inputs.NonIndexed().Pack(
operatorAddress.Bytes(),
common.BytesToAddress(operatorAddress.Bytes()),
name,
rewardAddress.Bytes(),
common.BytesToAddress(rewardAddress.Bytes()),
blsPubKey,
)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to pack CandidateRegisterWithBLS event")
}
topics := make(Topics, 3)
topics[0] = hash.Hash256(_candidateRegisteredEvent.ID)
topics[1] = hash.Hash256(candidate.Bytes())
topics[2] = hash.Hash256(ownerAddress.Bytes())
topics[1] = hash.BytesToHash256(candidate.Bytes())
topics[2] = hash.BytesToHash256(ownerAddress.Bytes())
return topics, data, nil
}

Expand All @@ -406,8 +406,8 @@ func PackStakedEvent(
}
topics := make(Topics, 3)
topics[0] = hash.Hash256(_stakedEvent.ID)
topics[1] = hash.Hash256(voter.Bytes())
topics[2] = hash.Hash256(candidate.Bytes())
topics[1] = hash.BytesToHash256(voter.Bytes())
topics[2] = hash.BytesToHash256(candidate.Bytes())
return topics, data, nil
}

Expand All @@ -422,7 +422,7 @@ func PackCandidateActivatedEvent(
}
topics := make(Topics, 2)
topics[0] = hash.Hash256(_candidateActivatedEvent.ID)
topics[1] = hash.Hash256(candidate.Bytes())
topics[1] = hash.BytesToHash256(candidate.Bytes())
return topics, data, nil
}

Expand Down
6 changes: 3 additions & 3 deletions action/candidate_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func PackCandidateUpdatedEvent(
blsPubKey []byte,
) (Topics, []byte, error) {
data, err := _candidateUpdateWithBLSEvent.Inputs.NonIndexed().Pack(
rewardAddress.Bytes(),
common.BytesToAddress(rewardAddress.Bytes()),
name,
common.BytesToAddress(operatorAddress.Bytes()),
blsPubKey,
Expand All @@ -302,7 +302,7 @@ func PackCandidateUpdatedEvent(
}
topics := make(Topics, 3)
topics[0] = hash.Hash256(_candidateUpdateWithBLSEvent.ID)
topics[1] = hash.Hash256(candidate.Bytes())
topics[2] = hash.Hash256(ownerAddress.Bytes())
topics[1] = hash.BytesToHash256(candidate.Bytes())
topics[2] = hash.BytesToHash256(ownerAddress.Bytes())
return topics, data, nil
}
102 changes: 102 additions & 0 deletions action/candidateregister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"github.com/iotexproject/go-pkgs/crypto"
"github.com/iotexproject/go-pkgs/hash"
"github.com/iotexproject/iotex-address/address"

"github.com/iotexproject/iotex-core/v2/test/identityset"
)
Expand Down Expand Up @@ -239,3 +242,102 @@ func TestIsValidCandidateName(t *testing.T) {
require.Equal(tt.output, output)
}
}

func TestStakingEvent(t *testing.T) {
require := require.New(t)
cand := identityset.Address(0)
owner := identityset.Address(1)
operator := identityset.Address(2)
reward := identityset.Address(3)
voter := identityset.Address(4)
blsPrivKey, err := crypto.GenerateBLS12381PrivateKey(identityset.PrivateKey(0).Bytes())
require.NoError(err)
blsPubKey := blsPrivKey.PublicKey().Bytes()
name := "test"

t.Run("register", func(t *testing.T) {
topics, data, err := PackCandidateRegisteredEvent(cand, operator, owner, name, reward, blsPubKey)
require.NoError(err)
checkCandidateRegisterEvent(require, topics, data, owner, cand, operator, reward, name, blsPubKey)
})
t.Run("staked", func(t *testing.T) {
bktIdx := uint64(1)
amount := big.NewInt(100)
duration := uint32(3600)
autoStake := true
topics, data, err := PackStakedEvent(voter, cand, bktIdx, amount, duration, autoStake)
require.NoError(err)
checkStakedEvent(require, topics, data, voter, cand, bktIdx, amount, duration, autoStake)
})
t.Run("activate", func(t *testing.T) {
bktIdx := uint64(1)
topics, data, err := PackCandidateActivatedEvent(cand, bktIdx)
require.NoError(err)
checkActivatedEvent(require, topics, data, cand, bktIdx)
})
t.Run("update", func(t *testing.T) {
topics, data, err := PackCandidateUpdatedEvent(cand, operator, owner, name, reward, blsPubKey)
require.NoError(err)
checkCandidateUpdateEvent(require, topics, data, owner, cand, operator, reward, name, blsPubKey)
})
}

func checkCandidateRegisterEvent(require *require.Assertions, topics Topics, data []byte,
owner, cand, operator, reward address.Address, name string, blsPubKey []byte,
) {
paramsNonIndexed, err := _candidateRegisteredEvent.Inputs.Unpack(data)
require.NoError(err)
require.Equal(4, len(paramsNonIndexed))
require.Equal(operator.Bytes(), paramsNonIndexed[0].(common.Address).Bytes())
require.Equal(name, paramsNonIndexed[1].(string))
require.Equal(reward.Bytes(), paramsNonIndexed[2].(common.Address).Bytes())
require.Equal(blsPubKey, paramsNonIndexed[3].([]byte))
require.Equal(3, len(topics))
require.Equal(hash.Hash256(_candidateRegisteredEvent.ID), topics[0])
require.Equal(hash.BytesToHash256(cand.Bytes()), topics[1])
require.Equal(hash.BytesToHash256(owner.Bytes()), topics[2])
}

func checkStakedEvent(require *require.Assertions, topics Topics, data []byte,
voter, cand address.Address, bktIdx uint64, amount *big.Int, duration uint32, autoStake bool,
) {
paramsNonIndexed, err := _stakedEvent.Inputs.Unpack(data)
require.NoError(err)
require.Equal(4, len(paramsNonIndexed))
require.Equal(bktIdx, paramsNonIndexed[0].(uint64))
require.Equal(amount, paramsNonIndexed[1].(*big.Int))
require.Equal(duration, paramsNonIndexed[2].(uint32))
require.Equal(autoStake, paramsNonIndexed[3].(bool))
require.Equal(3, len(topics))
require.Equal(hash.Hash256(_stakedEvent.ID), topics[0])
require.Equal(hash.BytesToHash256(voter.Bytes()), topics[1])
require.Equal(hash.BytesToHash256(cand.Bytes()), topics[2])
}

func checkActivatedEvent(require *require.Assertions, topics Topics, data []byte,
cand address.Address, bktIdx uint64,
) {
paramsNonIndexed, err := _candidateActivatedEvent.Inputs.Unpack(data)
require.NoError(err)
require.Equal(1, len(paramsNonIndexed))
require.Equal(bktIdx, paramsNonIndexed[0].(uint64))
require.Equal(2, len(topics))
require.Equal(hash.Hash256(_candidateActivatedEvent.ID), topics[0])
require.Equal(hash.BytesToHash256(cand.Bytes()), topics[1])
}

func checkCandidateUpdateEvent(require *require.Assertions, topics Topics, data []byte,
owner, cand, operator, reward address.Address, name string, blsPubKey []byte,
) {
paramsNonIndexed, err := _candidateUpdateWithBLSEvent.Inputs.Unpack(data)
require.NoError(err)
require.Equal(4, len(paramsNonIndexed))
require.Equal(reward.Bytes(), paramsNonIndexed[0].(common.Address).Bytes())
require.Equal(name, paramsNonIndexed[1].(string))
require.Equal(operator.Bytes(), paramsNonIndexed[2].(common.Address).Bytes())
require.Equal(blsPubKey, paramsNonIndexed[3].([]byte))
require.Equal(3, len(topics))
require.Equal(hash.Hash256(_candidateUpdateWithBLSEvent.ID), topics[0])
require.Equal(hash.BytesToHash256(cand.Bytes()), topics[1])
require.Equal(hash.BytesToHash256(owner.Bytes()), topics[2])
}
14 changes: 9 additions & 5 deletions action/protocol/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ type (
CandidateBLSPublicKey bool
NotUseMinSelfStakeToBeActive bool
StoreVoteOfNFTBucketIntoView bool
CandidateSlashByOwner bool
CandidateBLSPublicKeyNotCopied bool
}

// FeatureWithHeightCtx provides feature check functions.
Expand Down Expand Up @@ -325,10 +327,12 @@ func WithFeatureCtx(ctx context.Context) context.Context {
TimestampedStakingContract: g.IsWake(height),
PreStateSystemAction: !g.IsWake(height),
CreatePostActionStates: g.IsWake(height),
NotSlashUnproductiveDelegates: !g.IsToBeEnabled(height),
CandidateBLSPublicKey: g.IsToBeEnabled(height),
NotUseMinSelfStakeToBeActive: !g.IsToBeEnabled(height),
StoreVoteOfNFTBucketIntoView: !g.IsToBeEnabled(height),
NotSlashUnproductiveDelegates: !g.IsXingu(height),
CandidateBLSPublicKey: g.IsXingu(height),
NotUseMinSelfStakeToBeActive: !g.IsXingu(height),
StoreVoteOfNFTBucketIntoView: !g.IsXingu(height),
CandidateSlashByOwner: !g.IsXinguBeta(height),
CandidateBLSPublicKeyNotCopied: !g.IsXinguBeta(height),
},
)
}
Expand All @@ -351,7 +355,7 @@ func GetFeatureCtx(ctx context.Context) (FeatureCtx, bool) {
func MustGetFeatureCtx(ctx context.Context) FeatureCtx {
fc, ok := ctx.Value(featureContextKey{}).(FeatureCtx)
if !ok {
log.S().Panic("Miss feature context")
log.L().Panic("Miss feature context")
}
return fc
}
Expand Down
2 changes: 1 addition & 1 deletion action/protocol/execution/evm/evmstatedbadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ func (stateDB *StateDBAdapter) CommitContracts() error {
sort.Slice(contractAddrs, func(i, j int) bool { return bytes.Compare(contractAddrs[i][:], contractAddrs[j][:]) < 0 })

for _, addr := range contractAddrs {
_, err := stateDB.sm.DelState(protocol.KeyOption(addr[:]))
_, err := stateDB.sm.DelState(protocol.KeyOption(addr[:]), protocol.ObjectOption(&state.Account{}))
if stateDB.assertError(err, "failed to delete SelfDestruct account/contract", zap.Error(err), zap.String("address", addr.Hex())) {
return errors.Wrapf(err, "failed to delete SelfDestruct account/contract %x", addr[:])
}
Expand Down
17 changes: 13 additions & 4 deletions action/protocol/managers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,22 @@ func ObjectOption(obj any) StateOption {
}
}

// ErigonStoreOnlyOption sets the option to only read/write from/to erigon store
func ErigonStoreOnlyOption() StateOption {
return func(cfg *StateConfig) error {
cfg.ErigonStoreOnly = true
return nil
}
}

type (
// StateConfig is the config for accessing stateDB
StateConfig struct {
Namespace string // namespace used by state's storage
Key []byte
Keys [][]byte
Object any // object used by state's storage
Namespace string // namespace used by state's storage
Key []byte
Keys [][]byte
Object any // object used by state's storage
ErigonStoreOnly bool // whether only read/write from/to erigon store
}

// StateOption sets parameter for access state
Expand Down
39 changes: 39 additions & 0 deletions action/protocol/mock_protocol.go

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

6 changes: 3 additions & 3 deletions action/protocol/poll/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func validate(ctx context.Context, sr protocol.StateReader, p Protocol, act acti
}
for i, d := range ds {
if !proposedDelegates[i].Equal(d) {
msg := fmt.Sprintf(", %v vs %v (expected)",
proposedDelegates,
ds)
msg := fmt.Sprintf(", %+v vs %+v (expected)",
proposedDelegates[i],
d)
return errors.Wrap(ErrDelegatesNotAsExpected, msg)
}
}
Expand Down
2 changes: 1 addition & 1 deletion action/protocol/rewarding/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func testProtocol(t *testing.T, test func(*testing.T, context.Context, protocol.
g.Rewarding.NumDelegatesForFoundationBonus = 5
g.Rewarding.FoundationBonusLastEpoch = 365
g.Rewarding.ProductivityThreshold = 50
g.ToBeEnabledBlockHeight = slashHeight
g.XinguBlockHeight = slashHeight
// Initialize the protocol
if withExempt {
g.Rewarding.ExemptAddrStrsFromEpochReward = []string{
Expand Down
Loading