7
7
#include " commit_batcher_impl.hpp"
8
8
#include < iterator>
9
9
#include " vm/actor/builtin/v5/miner/miner_actor.hpp"
10
+ #include " vm/actor/builtin/v6/monies.hpp"
10
11
11
12
namespace fc ::mining {
12
- using fc::primitives::ActorId;
13
- using primitives::BigInt;
13
+ using api::kPushNoSpec ;
14
+ using fc::BytesIn;
15
+ using fc::proofs::ProofEngine;
16
+ using primitives::ActorId;
17
+ using primitives::go::bigdiv;
14
18
using primitives::sector::AggregateSealVerifyInfo;
19
+ using primitives::sector::AggregateSealVerifyProofAndInfos;
20
+ using primitives::tipset::TipsetCPtr;
21
+ using vm::actor::MethodParams;
15
22
using vm::actor::builtin::types::miner::kChainFinality ;
16
23
using vm::actor::builtin::types::miner::SectorPreCommitOnChainInfo;
17
24
using vm::actor::builtin::v5::miner::ProveCommitAggregate;
25
+ using vm::actor::builtin::v6::miner::AggregateProveCommitNetworkFee;
18
26
19
27
CommitBatcherImpl::CommitBatcherImpl (
20
28
const std::chrono::milliseconds &max_time,
@@ -74,21 +82,24 @@ namespace fc::mining {
74
82
}
75
83
OUTCOME_TRY (head, api_->ChainHead ());
76
84
77
- // TODO ?
78
85
const size_t total = union_storage_for_send.size ();
79
86
80
87
ProveCommitAggregate::Params params;
81
88
82
- std::vector<std::vector< uint8_t > > proofs;
89
+ std::vector<BytesIn > proofs;
83
90
proofs.reserve (total);
84
91
92
+ std::vector<AggregateSealVerifyInfo> infos;
93
+ infos.reserve (total);
94
+
85
95
BigInt collateral = 0 ;
86
96
87
97
for (const auto &[sector_number, pair_storage] : union_storage_for_send) {
88
98
OUTCOME_TRY (sc, getSectorCollateral (sector_number, head->key ));
89
99
collateral = collateral + sc;
90
100
91
101
params.sectors .insert (sector_number);
102
+ infos.push_back (pair_storage.aggregate_input .info );
92
103
}
93
104
94
105
for (const auto &[sector_number, pair_storage] : union_storage_for_send) {
@@ -98,28 +109,56 @@ namespace fc::mining {
98
109
const ActorId mid = miner_address_.getId ();
99
110
// TODO maybe long (AggregateSealProofs)
100
111
101
- // TODO params.proof = proof_->AggregateSealProofs(); // OUTCOME_TRY
102
- OUTCOME_TRY (a, proof_->AggregateSealProofs ());
103
-
104
- auto enc = codec::cbor::encode (params);
112
+ AggregateSealVerifyProofAndInfos aggregate_seal =
113
+ AggregateSealVerifyProofAndInfos{
114
+ .miner = mid,
115
+ .seal_proof =
116
+ union_storage_for_send[infos[0 ].number ].aggregate_input .spt ,
117
+ .aggregate_proof = arp_,
118
+ .proof = proofs[infos[0 ].number ], // TODO is it correct?
119
+ .infos = infos};
120
+
121
+ OUTCOME_TRY (proof_->aggregateSealProofs (aggregate_seal, proofs));
122
+ // need: std::vector<gsl::span<const uint8_t>>
123
+ // proofs: std::vector<std::vector<uint8_t>>
124
+ // proof: std::vector<uint8_t>
125
+ // BytesIn: gsl::span<const uint8_t>;
126
+
127
+ // proofs: std::vector<std::vector<uint8_t>>
128
+ auto b = gsl::make_span (proofs);
129
+ params.proof = aggregate_seal.proof ;
130
+ OUTCOME_TRY (enc, codec::cbor::encode (params));
105
131
OUTCOME_TRY (mi, api_->StateMinerInfo (miner_address_, head->key ));
106
132
107
- // BigDiv usage вместо /(обычное деление)
108
-
109
133
const TokenAmount max_fee =
110
134
fee_config_->max_commit_batch_gas_fee .FeeForSector (proofs.size ());
111
135
112
- /*
113
- * API_METHOD(StateMinerInfo,
114
- * jwt::kReadPermission,
115
- * MinerInfo,
116
- * const Address &,
117
- * const TipsetKey &)
118
- */
119
- // OTCOME_TRY(mi, api_->StateMinerInfo());
136
+ OUTCOME_TRY (ts, api_->ChainGetTipSet (head->key ));
137
+ const BigInt bf = ts->blks [0 ].parent_base_fee ;
120
138
121
- // TODO OUTCOME_TRY(bf, api_->ChainBaseFee(head));
122
139
OUTCOME_TRY (nv, api_->StateNetworkVersion (head->key ));
140
+
141
+ TokenAmount agg_fee_raw = AggregateProveCommitNetworkFee (infos.size (), bf);
142
+
143
+ TokenAmount agg_fee = bigdiv (agg_fee_raw * agg_fee_num_, agg_fee_den_);
144
+ TokenAmount need_funds = collateral + agg_fee;
145
+ TokenAmount good_funds = max_fee + need_funds;
146
+
147
+ OUTCOME_TRY (address, address_selector_ (mi, good_funds, need_funds, api_));
148
+ OUTCOME_TRY (mcid,
149
+ api_->MpoolPushMessage (
150
+ vm::message::UnsignedMessage (miner_address_,
151
+ address,
152
+ 0 ,
153
+ need_funds,
154
+ max_fee,
155
+ {},
156
+ ProveCommitAggregate::Number,
157
+ MethodParams{enc}),
158
+ kPushNoSpec ));
159
+
160
+ cutoff_start_ = std::chrono::system_clock::now ();
161
+ return mcid.getCid ();
123
162
}
124
163
125
164
void CommitBatcherImpl::setCommitCutoff (const ChainEpoch ¤t_epoch,
0 commit comments