9
9
#include " vm/actor/builtin/v5/miner/miner_actor.hpp"
10
10
11
11
namespace fc ::mining {
12
- using vm::actor::builtin::types::miner::kChainFinality ;
13
- using PairStorage = CommitBatcherImpl::UnionStorage::PairStorage;
14
12
using fc::primitives::ActorId;
15
13
using primitives::BigInt;
16
14
using primitives::sector::AggregateSealVerifyInfo;
15
+ using vm::actor::builtin::types::miner::kChainFinality ;
17
16
using vm::actor::builtin::types::miner::SectorPreCommitOnChainInfo;
18
17
using vm::actor::builtin::v5::miner::ProveCommitAggregate;
19
- namespace vm ::actor::builtin::types::miner::SectorPreCommitOnChainInfo;
20
18
21
19
CommitBatcherImpl::CommitBatcherImpl (
22
20
const std::chrono::milliseconds &max_time,
@@ -32,10 +30,12 @@ namespace fc::mining {
32
30
const SectorInfo §or_info,
33
31
const AggregateInput &aggregate_input,
34
32
const CommitCallback &callback) {
33
+ std::unique_lock<std::mutex> locker (mutex_storage_);
34
+
35
35
const SectorNumber §or_number = sector_info.sector_number ;
36
36
OUTCOME_TRY (head, api_->ChainHead ());
37
37
38
- union_storage_. push ( sector_number, PairStorage ( aggregate_input, callback)) ;
38
+ union_storage_[ sector_number] = PairStorage{ aggregate_input, callback} ;
39
39
40
40
if (union_storage_.size () >= max_size_callback_) {
41
41
sendCallbacks ();
@@ -49,7 +49,12 @@ namespace fc::mining {
49
49
void CommitBatcherImpl::forceSend () {}
50
50
51
51
void CommitBatcherImpl::sendCallbacks () {
52
- UnionStorage union_storage_for_send_ (std::move (union_storage_));
52
+ std::unique_lock<std::mutex> locker (mutex_storage_);
53
+ MapPairStorage union_storage_for_send_ (
54
+ std::make_move_iterator (union_storage_.begin ()),
55
+ std::make_move_iterator (union_storage_.end ()));
56
+ locker.unlock ();
57
+
53
58
const auto maybe_result = sendBatch (union_storage_for_send_);
54
59
for (const auto &[key, pair_storage] : union_storage_for_send_) {
55
60
pair_storage.commit_callback (maybe_result);
@@ -62,8 +67,8 @@ namespace fc::mining {
62
67
}
63
68
64
69
outcome::result<CID> CommitBatcherImpl::sendBatch (
65
- UnionStorage &union_storage_for_send) {
66
- if (not union_storage_for_send.size ()) {
70
+ MapPairStorage &union_storage_for_send) {
71
+ if (union_storage_for_send.empty ()) {
67
72
cutoff_start_ = std::chrono::system_clock::now ();
68
73
return ERROR_TEXT (" Empty Batcher" );
69
74
}
@@ -80,26 +85,24 @@ namespace fc::mining {
80
85
BigInt collateral = 0 ;
81
86
82
87
for (const auto &[sector_number, pair_storage] : union_storage_for_send) {
83
-
84
-
85
- TokenAmount sc = getSectorCollateral (head, sector_number, *head.get ());
88
+ OUTCOME_TRY (sc, getSectorCollateral (sector_number, head->key ));
86
89
collateral = collateral + sc;
87
90
88
91
params.sectors .insert (sector_number);
89
92
}
90
93
91
-
92
-
93
94
for (const auto &[sector_number, pair_storage] : union_storage_for_send) {
94
- proofs.push_back (
95
- pair_storage.aggregate_input .proof );
95
+ proofs.push_back (pair_storage.aggregate_input .proof );
96
96
}
97
97
98
98
const ActorId mid = miner_address_.getId ();
99
99
// TODO maybe long (AggregateSealProofs)
100
- params.proof = proof_->AggregateSealProofs (); // OUTCOME_TRY
101
100
102
- // TODO CBOR::ENCODE params
101
+ // TODO params.proof = proof_->AggregateSealProofs(); // OUTCOME_TRY
102
+ OUTCOME_TRY (a, proof_->AggregateSealProofs ());
103
+
104
+ auto enc = codec::cbor::encode (params);
105
+ OUTCOME_TRY (mi, api_->StateMinerInfo (miner_address_, head->key ));
103
106
104
107
// BigDiv usage вместо /(обычное деление)
105
108
@@ -115,16 +118,16 @@ namespace fc::mining {
115
118
*/
116
119
// OTCOME_TRY(mi, api_->StateMinerInfo());
117
120
118
- OUTCOME_TRY (bf, api_->ChainBaseFee (head));
119
- OUTCOME_TRY (nv, api_->StateNetworkVersion (/* NetworkVersion */ , head));
121
+ // TODO OUTCOME_TRY(bf, api_->ChainBaseFee(head));
122
+ OUTCOME_TRY (nv, api_->StateNetworkVersion (head-> key ));
120
123
}
121
124
122
125
void CommitBatcherImpl::setCommitCutoff (const ChainEpoch ¤t_epoch,
123
126
const SectorInfo §or_info) {
124
127
ChainEpoch cutoff_epoch =
125
128
sector_info.ticket_epoch
126
129
+ static_cast <int64_t >(kEpochsInDay + kChainFinality );
127
- ChainEpoch start_epoch{} ;
130
+ ChainEpoch start_epoch;
128
131
for (const auto &piece : sector_info.pieces ) {
129
132
if (!piece.deal_info ) {
130
133
continue ;
@@ -150,58 +153,20 @@ namespace fc::mining {
150
153
}
151
154
}
152
155
153
- TokenAmount CommitBatcherImpl::getSectorCollateral (
154
- std::shared_ptr<const Tipset> &head,
155
- const SectorNumber §or_number,
156
- const TipsetKey &tip_set_key) {
156
+ outcome::result<TokenAmount> CommitBatcherImpl::getSectorCollateral (
157
+ const SectorNumber §or_number, const TipsetKey &tip_set_key) {
157
158
OUTCOME_TRY (pci,
158
159
api_->StateSectorPreCommitInfo (
159
160
miner_address_, sector_number, tip_set_key));
161
+
160
162
OUTCOME_TRY (collateral,
161
163
api_->StateMinerInitialPledgeCollateral (
162
- miner_address_, head-> key , pci.info , tip_set_key));
164
+ miner_address_, pci.info , tip_set_key));
163
165
164
- collateral = collateral + pci.PreCommitDeposit ;
165
- collateral = max (0 , collateral);
166
+ collateral = collateral + pci.precommit_deposit ;
167
+ collateral = std:: max (BigInt ( 0 ) , collateral);
166
168
167
169
return collateral;
168
170
}
169
171
170
- void CommitBatcherImpl::UnionStorage::push (const SectorNumber §or_number,
171
- const PairStorage &pair_storage) {
172
- std::unique_lock<std::mutex> locker (mutex_);
173
- storage_[sector_number] = pair_storage;
174
- }
175
-
176
- CommitBatcherImpl::UnionStorage::UnionStorage (
177
- CommitBatcherImpl::UnionStorage &&union_storage1) {
178
- std::unique_lock<std::mutex> locker (union_storage1.mutex_ );
179
- storage_.insert (std::make_move_iterator (union_storage1.storage_ .begin ()),
180
- std::make_move_iterator (union_storage1.storage_ .end ()));
181
- }
182
-
183
- size_t CommitBatcherImpl::UnionStorage::size () {
184
- std::unique_lock<std::mutex> locker (mutex_);
185
- return storage_.size ();
186
- }
187
-
188
- CommitBatcherImpl::UnionStorage::PairStorage::PairStorage (
189
- const AggregateInput &aggregate_input,
190
- const CommitCallback &commit_callback)
191
- : aggregate_input(aggregate_input), commit_callback(commit_callback) {}
192
-
193
- std::map<SectorNumber, CommitBatcherImpl::UnionStorage::PairStorage>::iterator
194
- CommitBatcherImpl::UnionStorage::begin () {
195
- return storage_.begin ();
196
- }
197
-
198
- std::map<SectorNumber, CommitBatcherImpl::UnionStorage::PairStorage>::iterator
199
- CommitBatcherImpl::UnionStorage::end () {
200
- return storage_.end ();
201
- }
202
-
203
- PairStorage CommitBatcherImpl::UnionStorage::get (const int index) {
204
- std::unique_lock<std::mutex> locker (mutex_);
205
- return storage_[index ];
206
- }
207
172
} // namespace fc::mining
0 commit comments