Skip to content

Commit 6843e0b

Browse files
authored
[persistence/contract] do some rename (#538)
1 parent 9abd102 commit 6843e0b

File tree

10 files changed

+41
-45
lines changed

10 files changed

+41
-45
lines changed

cmd/stresstest/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func updateProjectRequiredProver(contractPersistence *contract.Contract, project
128128
project := projects[index]
129129
expectProvers := rand.Intn(len(provers)) + 1
130130

131-
tx, err := projectInstance.SetAttributes(opts, new(big.Int).SetUint64(project.ID), [][32]byte{contract.RequiredProverAmountHash}, [][]byte{[]byte(strconv.Itoa(expectProvers))})
131+
tx, err := projectInstance.SetAttributes(opts, new(big.Int).SetUint64(project.ID), [][32]byte{contract.RequiredProverAmount}, [][]byte{[]byte(strconv.Itoa(expectProvers))})
132132
if err != nil {
133133
slog.Error("failed to set project attributes", "error", err)
134134
return

persistence/contract/contract.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ const (
2828
)
2929

3030
var (
31-
allTopicHash = []common.Hash{
32-
attributeSetTopicHash,
33-
projectPausedTopicHash,
34-
projectResumedTopicHash,
35-
projectConfigUpdatedTopicHash,
31+
allTopic = []common.Hash{
32+
attributeSetTopic,
33+
projectPausedTopic,
34+
projectResumedTopic,
35+
projectConfigUpdatedTopic,
3636

37-
operatorSetTopicHash,
38-
nodeTypeUpdatedTopicHash,
39-
proverPausedTopicHash,
40-
proverResumedTopicHash,
37+
operatorSetTopic,
38+
nodeTypeUpdatedTopic,
39+
proverPausedTopic,
40+
proverResumedTopic,
4141
}
4242
)
4343

@@ -375,7 +375,7 @@ func (c *Contract) list() (uint64, error) {
375375
}
376376
query := ethereum.FilterQuery{
377377
Addresses: []common.Address{c.proverContractAddr, c.projectContractAddr},
378-
Topics: [][]common.Hash{allTopicHash},
378+
Topics: [][]common.Hash{allTopic},
379379
}
380380
from := head
381381
to := from
@@ -410,7 +410,7 @@ func (c *Contract) watch(listedBlockNumber uint64) {
410410
queriedBlockNumber := listedBlockNumber
411411
query := ethereum.FilterQuery{
412412
Addresses: []common.Address{c.proverContractAddr, c.projectContractAddr},
413-
Topics: [][]common.Hash{allTopicHash},
413+
Topics: [][]common.Hash{allTopic},
414414
}
415415
ticker := time.NewTicker(c.watchInterval)
416416

persistence/contract/project.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ import (
88
)
99

1010
var (
11-
RequiredProverAmountHash = crypto.Keccak256Hash([]byte("RequiredProverAmount"))
12-
VmTypeHash = crypto.Keccak256Hash([]byte("VmType"))
13-
ClientManagementContractAddressHash = crypto.Keccak256Hash([]byte("ClientManagementContractAddress"))
14-
15-
attributeSetTopicHash = crypto.Keccak256Hash([]byte("AttributeSet(uint256,bytes32,bytes)"))
16-
projectPausedTopicHash = crypto.Keccak256Hash([]byte("ProjectPaused(uint256)"))
17-
projectResumedTopicHash = crypto.Keccak256Hash([]byte("ProjectResumed(uint256)"))
18-
projectConfigUpdatedTopicHash = crypto.Keccak256Hash([]byte("ProjectConfigUpdated(uint256,string,bytes32)"))
19-
20-
emptyHash = common.Hash{}
11+
RequiredProverAmount = crypto.Keccak256Hash([]byte("RequiredProverAmount"))
12+
VmType = crypto.Keccak256Hash([]byte("VmType"))
13+
ClientManagementContractAddr = crypto.Keccak256Hash([]byte("ClientManagementContractAddress"))
14+
15+
attributeSetTopic = crypto.Keccak256Hash([]byte("AttributeSet(uint256,bytes32,bytes)"))
16+
projectPausedTopic = crypto.Keccak256Hash([]byte("ProjectPaused(uint256)"))
17+
projectResumedTopic = crypto.Keccak256Hash([]byte("ProjectResumed(uint256)"))
18+
projectConfigUpdatedTopic = crypto.Keccak256Hash([]byte("ProjectConfigUpdated(uint256,string,bytes32)"))
2119
)
2220

2321
type Project struct {
@@ -97,7 +95,7 @@ func (c *Contract) processProjectLogs(logs []types.Log) (map[uint64]*blockProjec
9795
}
9896
}
9997
switch l.Topics[0] {
100-
case attributeSetTopicHash:
98+
case attributeSetTopic:
10199
e, err := c.projectInstance.ParseAttributeSet(l)
102100
if err != nil {
103101
return nil, errors.Wrap(err, "failed to parse project attribute set event")
@@ -113,7 +111,7 @@ func (c *Contract) processProjectLogs(logs []types.Log) (map[uint64]*blockProjec
113111
p.attributes[e.Key] = e.Value
114112
ps.diffs[e.ProjectId.Uint64()] = p
115113

116-
case projectPausedTopicHash:
114+
case projectPausedTopic:
117115
e, err := c.projectInstance.ParseProjectPaused(l)
118116
if err != nil {
119117
return nil, errors.Wrap(err, "failed to parse project paused event")
@@ -130,7 +128,7 @@ func (c *Contract) processProjectLogs(logs []types.Log) (map[uint64]*blockProjec
130128
p.paused = &paused
131129
ps.diffs[e.ProjectId.Uint64()] = p
132130

133-
case projectResumedTopicHash:
131+
case projectResumedTopic:
134132
e, err := c.projectInstance.ParseProjectResumed(l)
135133
if err != nil {
136134
return nil, errors.Wrap(err, "failed to parse project resumed event")
@@ -147,7 +145,7 @@ func (c *Contract) processProjectLogs(logs []types.Log) (map[uint64]*blockProjec
147145
p.paused = &paused
148146
ps.diffs[e.ProjectId.Uint64()] = p
149147

150-
case projectConfigUpdatedTopicHash:
148+
case projectConfigUpdatedTopic:
151149
e, err := c.projectInstance.ParseProjectConfigUpdated(l)
152150
if err != nil {
153151
return nil, errors.Wrap(err, "failed to parse project config updated event")

persistence/contract/prover.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import (
88
)
99

1010
var (
11-
operatorSetTopicHash = crypto.Keccak256Hash([]byte("OperatorSet(uint256,address)"))
12-
nodeTypeUpdatedTopicHash = crypto.Keccak256Hash([]byte("NodeTypeUpdated(uint256,uint256)"))
13-
proverPausedTopicHash = crypto.Keccak256Hash([]byte("ProverPaused(uint256)"))
14-
proverResumedTopicHash = crypto.Keccak256Hash([]byte("ProverResumed(uint256)"))
15-
16-
emptyAddress = common.Address{}
11+
operatorSetTopic = crypto.Keccak256Hash([]byte("OperatorSet(uint256,address)"))
12+
nodeTypeUpdatedTopic = crypto.Keccak256Hash([]byte("NodeTypeUpdated(uint256,uint256)"))
13+
proverPausedTopic = crypto.Keccak256Hash([]byte("ProverPaused(uint256)"))
14+
proverResumedTopic = crypto.Keccak256Hash([]byte("ProverResumed(uint256)"))
1715
)
1816

1917
type Prover struct {
@@ -87,7 +85,7 @@ func (c *Contract) processProverLogs(logs []types.Log) (map[uint64]*blockProverD
8785
}
8886
}
8987
switch l.Topics[0] {
90-
case operatorSetTopicHash:
88+
case operatorSetTopic:
9189
e, err := c.proverInstance.ParseOperatorSet(l)
9290
if err != nil {
9391
return nil, errors.Wrap(err, "failed to parse prover operator set event")
@@ -100,7 +98,7 @@ func (c *Contract) processProverLogs(logs []types.Log) (map[uint64]*blockProverD
10098
p.operatorAddress = &e.Operator
10199
ps.diffs[e.Id.Uint64()] = p
102100

103-
case nodeTypeUpdatedTopicHash:
101+
case nodeTypeUpdatedTopic:
104102
e, err := c.proverInstance.ParseNodeTypeUpdated(l)
105103
if err != nil {
106104
return nil, errors.Wrap(err, "failed to parse prover node type updated event")
@@ -114,7 +112,7 @@ func (c *Contract) processProverLogs(logs []types.Log) (map[uint64]*blockProverD
114112
p.nodeTypes = &nt
115113
ps.diffs[e.Id.Uint64()] = p
116114

117-
case proverPausedTopicHash:
115+
case proverPausedTopic:
118116
e, err := c.proverInstance.ParseProverPaused(l)
119117
if err != nil {
120118
return nil, errors.Wrap(err, "failed to parse prover paused event")
@@ -128,7 +126,7 @@ func (c *Contract) processProverLogs(logs []types.Log) (map[uint64]*blockProverD
128126
p.paused = &paused
129127
ps.diffs[e.Id.Uint64()] = p
130128

131-
case proverResumedTopicHash:
129+
case proverResumedTopic:
132130
e, err := c.proverInstance.ParseProverResumed(l)
133131
if err != nil {
134132
return nil, errors.Wrap(err, "failed to parse prover resumed event")

scheduler/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *scheduler) schedule() {
6565
}
6666

6767
amount := uint64(1)
68-
if v, ok := cp.Attributes[contract.RequiredProverAmountHash]; ok {
68+
if v, ok := cp.Attributes[contract.RequiredProverAmount]; ok {
6969
n, err := strconv.ParseUint(string(v), 10, 64)
7070
if err != nil {
7171
slog.Error("failed to parse project required prover amount", "project_id", projectID)

scheduler/scheduler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestScheduler_schedule(t *testing.T) {
100100
p.ApplyMethodReturn(pes, "Projects", []*ScheduledProject{{1, 0}})
101101
p.ApplyMethodReturn(pm, "Provers", []*contract.Prover{{ID: 1, Paused: paused}})
102102
p.ApplyMethodReturn(pm, "Project", &contract.Project{
103-
Attributes: map[common.Hash][]byte{contract.RequiredProverAmountHash: []byte("err")},
103+
Attributes: map[common.Hash][]byte{contract.RequiredProverAmount: []byte("err")},
104104
})
105105

106106
chainHead := make(chan uint64, 10)
@@ -130,7 +130,7 @@ func TestScheduler_schedule(t *testing.T) {
130130
p.ApplyMethodReturn(pes, "Projects", []*ScheduledProject{{1, 0}})
131131
p.ApplyMethodReturn(pm, "Provers", []*contract.Prover{{ID: 1, Paused: paused}})
132132
p.ApplyMethodReturn(pm, "Project", &contract.Project{
133-
Attributes: map[common.Hash][]byte{contract.RequiredProverAmountHash: []byte("10")},
133+
Attributes: map[common.Hash][]byte{contract.RequiredProverAmount: []byte("10")},
134134
})
135135
p.ApplyMethodReturn(&p2p.PubSubs{}, "Delete")
136136

task/dispatcher/dispatcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (d *Dispatcher) setRequiredProverAmount(head uint64) {
8585
}
8686

8787
proverAmount := uint64(1)
88-
if v, ok := cp.Attributes[contract.RequiredProverAmountHash]; ok {
88+
if v, ok := cp.Attributes[contract.RequiredProverAmount]; ok {
8989
n, err := strconv.ParseUint(string(v), 10, 64)
9090
if err != nil {
9191
slog.Error("failed to parse project required prover amount when set window size", "project_id", p.ID)

task/dispatcher/dispatcher_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestDispatcher_setRequiredProverAmount(t *testing.T) {
104104
p.ApplyMethodReturn(po, "Projects", []*scheduler.ScheduledProject{{ID: 1, ScheduledBlockNumber: 0}})
105105
p.ApplyMethodReturn(c, "Project", &contract.Project{
106106
ID: 1,
107-
Attributes: map[common.Hash][]byte{contract.RequiredProverAmountHash: []byte("err")},
107+
Attributes: map[common.Hash][]byte{contract.RequiredProverAmount: []byte("err")},
108108
})
109109
d.projectDispatchers.Store(uint64(1), &projectDispatcher{})
110110
d.setRequiredProverAmount(1)
@@ -116,7 +116,7 @@ func TestDispatcher_setRequiredProverAmount(t *testing.T) {
116116
p.ApplyMethodReturn(po, "Projects", []*scheduler.ScheduledProject{{ID: 1, ScheduledBlockNumber: 0}})
117117
p.ApplyMethodReturn(c, "Project", &contract.Project{
118118
ID: 1,
119-
Attributes: map[common.Hash][]byte{contract.RequiredProverAmountHash: []byte("2")},
119+
Attributes: map[common.Hash][]byte{contract.RequiredProverAmount: []byte("2")},
120120
})
121121
size := atomic.Uint64{}
122122
d.projectDispatchers.Store(uint64(1), &projectDispatcher{

task/dispatcher/project_dispatcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func newProjectDispatcher(persistence Persistence, datasourceURI string, newData
9292

9393
proverAmount := &atomic.Uint64{}
9494
proverAmount.Store(1)
95-
if v, ok := p.Attributes[contract.RequiredProverAmountHash]; ok {
95+
if v, ok := p.Attributes[contract.RequiredProverAmount]; ok {
9696
n, err := strconv.ParseUint(string(v), 10, 64)
9797
if err != nil {
9898
return nil, errors.Wrapf(err, "failed to parse project required prover amount, project_id %v", p.ID)

task/dispatcher/project_dispatcher_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func TestNewProjectDispatcher(t *testing.T) {
165165
nd := func(string) (datasource.Datasource, error) { return nil, nil }
166166

167167
_, err := newProjectDispatcher(ps, "", nd, &contract.Project{
168-
Attributes: map[common.Hash][]byte{contract.RequiredProverAmountHash: []byte("err")},
168+
Attributes: map[common.Hash][]byte{contract.RequiredProverAmount: []byte("err")},
169169
}, nil, nil, nil)
170170
r.ErrorContains(err, "failed to parse project required prover amount")
171171
})
@@ -181,7 +181,7 @@ func TestNewProjectDispatcher(t *testing.T) {
181181

182182
paused := true
183183
_, err := newProjectDispatcher(ps, "", nd, &contract.Project{
184-
Attributes: map[common.Hash][]byte{contract.RequiredProverAmountHash: []byte("1")},
184+
Attributes: map[common.Hash][]byte{contract.RequiredProverAmount: []byte("1")},
185185
Paused: paused,
186186
}, nil, nil, nil)
187187
time.Sleep(10 * time.Millisecond)

0 commit comments

Comments
 (0)