Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions action/protocol/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ type (
NotSlashUnproductiveDelegates bool
CandidateBLSPublicKey bool
NotUseMinSelfStakeToBeActive bool
LoadContractStakingFromIndexer bool
}

// FeatureWithHeightCtx provides feature check functions.
Expand Down Expand Up @@ -327,6 +328,7 @@ func WithFeatureCtx(ctx context.Context) context.Context {
NotSlashUnproductiveDelegates: !g.IsToBeEnabled(height),
CandidateBLSPublicKey: g.IsToBeEnabled(height),
NotUseMinSelfStakeToBeActive: !g.IsToBeEnabled(height),
LoadContractStakingFromIndexer: !g.IsToBeEnabled(height),
},
)
}
Expand Down
2 changes: 1 addition & 1 deletion 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/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type (
Fork() View
Snapshot() int
Revert(int) error
Commit(context.Context, StateReader) error
Commit(context.Context, StateManager) error
}

// Views stores the view for all protocols
Expand All @@ -138,9 +138,9 @@ func (views *Views) Fork() *Views {
return fork
}

func (views *Views) Commit(ctx context.Context, sr StateReader) error {
func (views *Views) Commit(ctx context.Context, sm StateManager) error {
for _, view := range views.vm {
if err := view.Commit(ctx, sr); err != nil {
if err := view.Commit(ctx, sm); err != nil {
return err
}
}
Expand Down
12 changes: 6 additions & 6 deletions action/protocol/staking/bucket_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,26 @@ func TestGetPutBucketIndex(t *testing.T) {

// put buckets and get
for i, e := range tests {
_, _, err := csr.voterBucketIndices(e.voterAddr)
_, _, err := csr.NativeBucketIndicesByVoter(e.voterAddr)
if i == 0 {
require.Equal(state.ErrStateNotExist, errors.Cause(err))
}
_, _, err = csr.candBucketIndices(e.candAddr)
_, _, err = csr.NativeBucketIndicesByCandidate(e.candAddr)
if i == 0 {
require.Equal(state.ErrStateNotExist, errors.Cause(err))
}

// put voter bucket index
require.NoError(csm.putVoterBucketIndex(e.voterAddr, e.index))
bis, _, err := csr.voterBucketIndices(e.voterAddr)
bis, _, err := csr.NativeBucketIndicesByVoter(e.voterAddr)
require.NoError(err)
bucketIndices := *bis
require.Equal(e.voterIndexSize, len(bucketIndices))
require.Equal(bucketIndices[e.voterIndexSize-1], e.index)

// put candidate bucket index
require.NoError(csm.putCandBucketIndex(e.candAddr, e.index))
bis, _, err = csr.candBucketIndices(e.candAddr)
bis, _, err = csr.NativeBucketIndicesByCandidate(e.candAddr)
require.NoError(err)
bucketIndices = *bis
require.Equal(e.candIndexSize, len(bucketIndices))
Expand All @@ -152,7 +152,7 @@ func TestGetPutBucketIndex(t *testing.T) {
for _, e := range tests {
// delete voter bucket index
require.NoError(csm.delVoterBucketIndex(e.voterAddr, e.index))
bis, _, err := csr.voterBucketIndices(e.voterAddr)
bis, _, err := csr.NativeBucketIndicesByVoter(e.voterAddr)
if e.voterIndexSize != indexSize {
bucketIndices := *bis
require.Equal(indexSize-e.voterIndexSize, len(bucketIndices))
Expand All @@ -162,7 +162,7 @@ func TestGetPutBucketIndex(t *testing.T) {

// delete candidate bucket index
require.NoError(csm.delCandBucketIndex(e.candAddr, e.index))
bis, _, err = csr.candBucketIndices(e.candAddr)
bis, _, err = csr.NativeBucketIndicesByCandidate(e.candAddr)
if e.candIndexSize != indexSize {
bucketIndices := *bis
require.Equal(indexSize-e.candIndexSize, len(bucketIndices))
Expand Down
2 changes: 1 addition & 1 deletion action/protocol/staking/bucket_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (bp *BucketPool) Clone() *BucketPool {
}

// Commit is called upon workingset commit
func (bp *BucketPool) Commit(sr protocol.StateReader) error {
func (bp *BucketPool) Commit() error {
bp.dirty = false
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions action/protocol/staking/candidate_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func (m *CandidateCenter) commit() error {
}

// Commit writes the change into base
func (m *CandidateCenter) Commit(ctx context.Context, sr protocol.StateReader) error {
height, err := sr.Height()
func (m *CandidateCenter) Commit(ctx context.Context, sm protocol.StateManager) error {
height, err := sm.Height()
if err != nil {
return err
}
Expand Down Expand Up @@ -292,8 +292,8 @@ func (m *CandidateCenter) WriteToStateDB(sm protocol.StateManager) error {
name := m.base.candsInNameMap()
op := m.base.candsInOperatorMap()
owners := m.base.ownersList()
if len(name) == 0 || len(op) == 0 {
return ErrNilParameters
if len(name) == 0 || len(op) == 0 || len(owners) == 0 {
return nil
}
if _, err := sm.PutState(name, protocol.NamespaceOption(CandsMapNS), protocol.KeyOption(_nameKey)); err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions action/protocol/staking/candidate_center_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func TestFixAlias(t *testing.T) {
} else {
r.NoError(m.commit())
}
views.Write(_protocolID, &ViewData{
views.Write(_protocolID, &viewData{
candCenter: m,
})

Expand Down Expand Up @@ -376,7 +376,7 @@ func TestFixAlias(t *testing.T) {
} else {
r.NoError(center.commit())
}
views.Write(_protocolID, &ViewData{
views.Write(_protocolID, &viewData{
candCenter: center,
})
}
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestMultipleNonStakingCandidate(t *testing.T) {
r.True(testEqual(candcenter, CandidateList(cands)))
// from state manager
views := protocol.NewViews()
views.Write(_protocolID, &ViewData{
views.Write(_protocolID, &viewData{
candCenter: candcenter,
})
candcenter = candCenterFromNewCandidateStateManager(r, views)
Expand Down Expand Up @@ -538,7 +538,7 @@ func candCenterFromNewCandidateStateManager(r *require.Assertions, views *protoc
// get cand center: csm.ConstructBaseView
v, err := views.Read(_protocolID)
r.NoError(err)
return v.(*ViewData).candCenter
return v.(*viewData).candCenter
}

func TestCandidateUpsert(t *testing.T) {
Expand Down
18 changes: 9 additions & 9 deletions action/protocol/staking/candidate_statemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ type (
// CandidateStateManager is candidate state manager on top of StateManager
CandidateStateManager interface {
BucketSet
BucketGetByIndex
NativeBucketGetByIndex
CandidateSet
// candidate and bucket pool related
DirtyView() *ViewData
DirtyView() *viewData
ContainsName(string) bool
ContainsOwner(address.Address) bool
ContainsOperator(address.Address) bool
Expand All @@ -64,7 +64,7 @@ type (
ContainsSelfStakingBucket(uint64) bool
GetByIdentifier(address.Address) *Candidate
SR() protocol.StateReader
BucketGetByIndex
NativeBucketGetByIndex
}

candSM struct {
Expand Down Expand Up @@ -108,15 +108,15 @@ func (csm *candSM) SR() protocol.StateReader {
}

// DirtyView is csm's current state, which reflects base view + applying delta saved in csm's dock
func (csm *candSM) DirtyView() *ViewData {
func (csm *candSM) DirtyView() *viewData {
v, err := csm.StateManager.ReadView(_protocolID)
if err != nil {
log.S().Panic("failed to read view", zap.Error(err))
}
return &ViewData{
return &viewData{
candCenter: csm.candCenter,
bucketPool: csm.bucketPool,
contractsStake: v.(*ViewData).contractsStake,
contractsStake: v.(*viewData).contractsStake,
}
}

Expand Down Expand Up @@ -175,12 +175,12 @@ func (csm *candSM) Commit(ctx context.Context) error {
return csm.WriteView(_protocolID, view)
}

func (csm *candSM) getBucket(index uint64) (*VoteBucket, error) {
return newCandidateStateReader(csm).getBucket(index)
func (csm *candSM) NativeBucket(index uint64) (*VoteBucket, error) {
return newCandidateStateReader(csm).NativeBucket(index)
}

func (csm *candSM) updateBucket(index uint64, bucket *VoteBucket) error {
if _, err := csm.getBucket(index); err != nil {
if _, err := csm.NativeBucket(index); err != nil {
return err
}

Expand Down
Loading