Skip to content

Commit 9cb00b8

Browse files
committed
Remove simulator autofarm support.
1 parent 0c1f2a9 commit 9cb00b8

10 files changed

Lines changed: 36 additions & 130 deletions

File tree

crates/chia-sdk-bindings/src/full_node_simulator.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ impl FullNodeSimulator {
7474
Ok(())
7575
}
7676

77-
pub fn get_autofarm(&self) -> Result<bool> {
78-
Ok(self.0.lock().unwrap().get_autofarm())
79-
}
80-
81-
pub fn set_autofarm(&self, autofarm: bool) -> Result<()> {
82-
self.0.lock().unwrap().set_autofarm(autofarm);
83-
Ok(())
84-
}
85-
8677
pub fn get_blockchain_state(&self) -> Result<BlockchainStateResponse> {
8778
Ok(self.0.lock().unwrap().get_blockchain_state())
8879
}

crates/chia-sdk-test/src/full_node_simulator.rs

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub struct FullNodeSimulator {
5656
coin_spends: IndexMap<Bytes32, CoinSpend>,
5757
coin_hints: IndexMap<Bytes32, Bytes32>,
5858
mempool: IndexMap<Bytes32, ValidatedBundle>,
59-
autofarm: bool,
6059
farming_puzzle_hash: Bytes32,
6160
master_secret_key: SecretKey,
6261
prefarm_puzzle_hash: Bytes32,
@@ -254,7 +253,6 @@ impl FullNodeSimulator {
254253
coin_spends: IndexMap::new(),
255254
coin_hints: IndexMap::new(),
256255
mempool: IndexMap::new(),
257-
autofarm: true,
258256
farming_puzzle_hash: prefarm_puzzle_hash,
259257
master_secret_key: root_secret_key,
260258
prefarm_puzzle_hash,
@@ -309,14 +307,6 @@ impl FullNodeSimulator {
309307
self.farming_puzzle_hash = puzzle_hash;
310308
}
311309

312-
pub fn get_autofarm(&self) -> bool {
313-
self.autofarm
314-
}
315-
316-
pub fn set_autofarm(&mut self, autofarm: bool) {
317-
self.autofarm = autofarm;
318-
}
319-
320310
pub fn get_blockchain_state(&self) -> BlockchainStateResponse {
321311
let peak = self
322312
.blocks
@@ -595,9 +585,6 @@ impl FullNodeSimulator {
595585
loop {
596586
let tx_id = spend_bundle.name();
597587
if self.mempool.contains_key(&tx_id) {
598-
if self.autofarm {
599-
self.farm_block(1);
600-
}
601588
return push_tx_success();
602589
}
603590

@@ -621,10 +608,6 @@ impl FullNodeSimulator {
621608

622609
match self.insert_mempool_item(tx_id, validated.clone()) {
623610
Ok(()) => {
624-
if self.autofarm {
625-
self.farm_block(1);
626-
}
627-
628611
return push_tx_success();
629612
}
630613
Err(SimulatorError::Validation(ErrorCode::MempoolConflict))
@@ -952,15 +935,24 @@ mod tests {
952935
}
953936

954937
#[test]
955-
fn push_tx_autofarms_by_default() -> anyhow::Result<()> {
938+
fn push_tx_waits_for_manual_farming() -> anyhow::Result<()> {
956939
let mut sim = FullNodeSimulator::new();
957940
let (puzzle_hash, puzzle_reveal) = to_puzzle(1)?;
958941
let coin = sim.new_coin(puzzle_hash, 100);
959942
let spend_bundle = spend_to_child(coin, puzzle_reveal, puzzle_hash, 99)?;
960943

961-
assert!(sim.get_autofarm());
962944
let response = sim.push_tx(spend_bundle);
963945
assert!(response.success);
946+
assert_eq!(
947+
sim.get_blockchain_state()
948+
.blockchain_state
949+
.unwrap()
950+
.mempool_size,
951+
1
952+
);
953+
assert_eq!(sim.height(), 1);
954+
955+
sim.farm_block(1);
964956
assert_eq!(
965957
sim.get_blockchain_state()
966958
.blockchain_state
@@ -990,7 +982,6 @@ mod tests {
990982
#[test]
991983
fn farm_block_includes_mempool_and_emits_event() -> anyhow::Result<()> {
992984
let mut sim = FullNodeSimulator::new();
993-
sim.set_autofarm(false);
994985
let (puzzle_hash, puzzle_reveal) = to_puzzle(1)?;
995986
let coin = sim.new_coin(puzzle_hash, 100);
996987
let child = Coin::new(coin.coin_id(), puzzle_hash, 99);
@@ -1061,7 +1052,6 @@ mod tests {
10611052
#[test]
10621053
fn push_tx_accepts_ephemeral_spends_in_same_bundle() -> anyhow::Result<()> {
10631054
let mut sim = FullNodeSimulator::new();
1064-
sim.set_autofarm(false);
10651055
let (puzzle_hash, puzzle_reveal) = to_puzzle(1)?;
10661056
let parent = sim.new_coin(puzzle_hash, 100);
10671057
let child = Coin::new(parent.coin_id(), puzzle_hash, 99);
@@ -1105,40 +1095,6 @@ mod tests {
11051095
Ok(())
11061096
}
11071097

1108-
#[test]
1109-
fn autofarm_can_be_turned_off_and_on() -> anyhow::Result<()> {
1110-
let mut sim = FullNodeSimulator::new();
1111-
let (puzzle_hash, puzzle_reveal) = to_puzzle(1)?;
1112-
let coin = sim.new_coin(puzzle_hash, 100);
1113-
let spend_bundle = spend_to_child(coin, puzzle_reveal, puzzle_hash, 99)?;
1114-
1115-
sim.set_autofarm(false);
1116-
assert!(!sim.get_autofarm());
1117-
assert!(sim.push_tx(spend_bundle.clone()).success);
1118-
assert_eq!(
1119-
sim.get_blockchain_state()
1120-
.blockchain_state
1121-
.unwrap()
1122-
.mempool_size,
1123-
1
1124-
);
1125-
assert_eq!(sim.height(), 1);
1126-
1127-
sim.set_autofarm(true);
1128-
assert!(sim.get_autofarm());
1129-
assert!(sim.push_tx(spend_bundle).success);
1130-
assert_eq!(sim.height(), 2);
1131-
assert_eq!(
1132-
sim.get_blockchain_state()
1133-
.blockchain_state
1134-
.unwrap()
1135-
.mempool_size,
1136-
0
1137-
);
1138-
1139-
Ok(())
1140-
}
1141-
11421098
#[test]
11431099
fn revert_removes_farmed_reward() {
11441100
let mut sim = FullNodeSimulator::new();

crates/chia-sdk-test/src/full_node_simulator/fast_forward.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ mod tests {
363363

364364
let response = sim.push_tx(stale_bundle);
365365
assert!(response.success, "{response:?}");
366+
sim.farm_block(1);
366367

367368
let child_record = sim
368369
.get_coin_record_by_name(child_coin.coin_id())

crates/chia-sdk-test/src/full_node_simulator/mempool.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ mod tests {
106106
#[test]
107107
fn push_tx_rejects_mempool_conflict() -> anyhow::Result<()> {
108108
let mut sim = FullNodeSimulator::new();
109-
sim.set_autofarm(false);
110109
let (puzzle_hash, puzzle_reveal) = to_puzzle(1)?;
111110
let coin = sim.new_coin(puzzle_hash, 100);
112111
let first = spend_to_child(coin, puzzle_reveal.clone(), puzzle_hash, 98)?;
@@ -134,7 +133,6 @@ mod tests {
134133
#[test]
135134
fn push_tx_replaces_mempool_conflict_with_higher_fee_superset() -> anyhow::Result<()> {
136135
let mut sim = FullNodeSimulator::new();
137-
sim.set_autofarm(false);
138136
let (puzzle_hash, puzzle_reveal) = to_puzzle(1)?;
139137
let coin = sim.new_coin(puzzle_hash, 100);
140138
let first = spend_to_child(coin, puzzle_reveal.clone(), puzzle_hash, 99)?;
@@ -169,7 +167,6 @@ mod tests {
169167
#[test]
170168
fn push_tx_does_not_replace_conflict_that_is_not_a_superset() -> anyhow::Result<()> {
171169
let mut sim = FullNodeSimulator::new();
172-
sim.set_autofarm(false);
173170
let (puzzle_hash, puzzle_reveal) = to_puzzle(1)?;
174171
let coin_a = sim.new_coin(puzzle_hash, 100);
175172
let coin_b = sim.new_coin(puzzle_hash, 100);
@@ -206,7 +203,6 @@ mod tests {
206203
#[test]
207204
fn push_tx_allows_dedup_compatible_mempool_overlap() -> anyhow::Result<()> {
208205
let mut sim = FullNodeSimulator::new();
209-
sim.set_autofarm(false);
210206
let (puzzle_hash, puzzle_reveal) = to_puzzle(1)?;
211207
let shared_coin = sim.new_coin(puzzle_hash, 100);
212208
let extra_coin = sim.new_coin(puzzle_hash, 100);

crates/chia-sdk-test/src/full_node_simulator_http/handlers.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use super::{
1414
GetAggsigAdditionalDataResponse, HeaderHashRequest, HeightRequest, HintRequest,
1515
HintsRequest, InsertCoinRequest, NameRequest, NamesRequest, NewCoinRequest,
1616
ParentIdsRequest, PushTxRequest, PuzzleAndSolutionRequest, PuzzleHashRequest,
17-
PuzzleHashesRequest, ReorgBlocksRequest, RevertBlocksRequest, SetAutofarmRequest,
18-
SetFarmingPhRequest, SimEventsResponse, SimFarmBlockResponse, SimNewCoinResponse,
19-
SimRevertBlocksResponse, SimSuccessResponse, TxIdRequest,
17+
PuzzleHashesRequest, ReorgBlocksRequest, RevertBlocksRequest, SetFarmingPhRequest,
18+
SimEventsResponse, SimFarmBlockResponse, SimNewCoinResponse, SimRevertBlocksResponse,
19+
SimSuccessResponse, TxIdRequest,
2020
},
2121
};
2222

@@ -78,7 +78,6 @@ pub(super) fn router(simulator: SharedSimulator) -> Router {
7878
.route("/sim/reorg_blocks", post(sim_reorg_blocks))
7979
.route("/sim/new_coin", post(sim_new_coin))
8080
.route("/sim/insert_coin", post(sim_insert_coin))
81-
.route("/sim/set_autofarm", post(sim_set_autofarm))
8281
.route("/sim/set_farming_ph", post(sim_set_farming_ph))
8382
.route("/sim/drain_events", post(sim_drain_events))
8483
.with_state(simulator)
@@ -382,14 +381,6 @@ async fn sim_insert_coin(
382381
Json(SimSuccessResponse { success: true })
383382
}
384383

385-
async fn sim_set_autofarm(
386-
State(simulator): State<SharedSimulator>,
387-
Json(request): Json<SetAutofarmRequest>,
388-
) -> Json<SimSuccessResponse> {
389-
simulator.lock().unwrap().set_autofarm(request.autofarm);
390-
Json(SimSuccessResponse { success: true })
391-
}
392-
393384
async fn sim_set_farming_ph(
394385
State(simulator): State<SharedSimulator>,
395386
Json(request): Json<SetFarmingPhRequest>,

crates/chia-sdk-test/src/full_node_simulator_http/tests.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ use crate::{
1414
use super::{
1515
push_tx::push_tx_response_body,
1616
server::FullNodeSimulatorServer,
17-
types::{
18-
GetAggsigAdditionalDataResponse, SimFarmBlockResponse, SimNewCoinResponse,
19-
SimSuccessResponse,
20-
},
17+
types::{GetAggsigAdditionalDataResponse, SimFarmBlockResponse, SimNewCoinResponse},
2118
};
2219

2320
#[tokio::test]
@@ -48,15 +45,6 @@ async fn rpc_client_can_drive_http_simulator() -> anyhow::Result<()> {
4845
assert_eq!(additional_data.len(), 64);
4946
assert!(!additional_data.starts_with("0x"));
5047

51-
let response = http
52-
.post(format!("{}/sim/set_autofarm", server.url()))
53-
.json(&serde_json::json!({ "autofarm": false }))
54-
.send()
55-
.await?
56-
.json::<SimSuccessResponse>()
57-
.await?;
58-
assert!(response.success);
59-
6048
let (puzzle_hash, puzzle_reveal) = to_puzzle(1)?;
6149
let new_coin = http
6250
.post(format!("{}/sim/new_coin", server.url()))
@@ -212,10 +200,6 @@ async fn get_coin_records_by_puzzle_hashes_uses_exclusive_end_height() -> anyhow
212200
let server = FullNodeSimulatorServer::new().await?;
213201
let client = CoinsetClient::new(server.url());
214202
let http = reqwest::Client::new();
215-
http.post(format!("{}/sim/set_autofarm", server.url()))
216-
.json(&serde_json::json!({ "autofarm": false }))
217-
.send()
218-
.await?;
219203

220204
let (parent_puzzle_hash, parent_puzzle_reveal) = to_puzzle(1)?;
221205
let (child_puzzle_hash, _) = to_puzzle(2)?;
@@ -273,10 +257,6 @@ async fn get_coin_records_by_puzzle_hashes_passes_through_include_spent_coins()
273257
let server = FullNodeSimulatorServer::new().await?;
274258
let client = CoinsetClient::new(server.url());
275259
let http = reqwest::Client::new();
276-
http.post(format!("{}/sim/set_autofarm", server.url()))
277-
.json(&serde_json::json!({ "autofarm": false }))
278-
.send()
279-
.await?;
280260

281261
let (historical_puzzle_hash, historical_puzzle_reveal) = to_puzzle(1)?;
282262
let parent = http
@@ -473,10 +453,6 @@ async fn unsupported_endpoints_and_cursor_policy_are_explicit() -> anyhow::Resul
473453
async fn push_tx_returns_pending_for_mempool_conflict() -> anyhow::Result<()> {
474454
let server = FullNodeSimulatorServer::new().await?;
475455
let http = reqwest::Client::new();
476-
http.post(format!("{}/sim/set_autofarm", server.url()))
477-
.json(&serde_json::json!({ "autofarm": false }))
478-
.send()
479-
.await?;
480456

481457
let (puzzle_hash, puzzle_reveal) = to_puzzle(1)?;
482458
let coin = http

crates/chia-sdk-test/src/full_node_simulator_http/types.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ pub(super) struct InsertCoinRequest {
147147
pub(super) coin: Coin,
148148
}
149149

150-
#[derive(Debug, Deserialize)]
151-
pub(super) struct SetAutofarmRequest {
152-
pub(super) autofarm: bool,
153-
}
154-
155150
#[derive(Debug, Deserialize)]
156151
pub(super) struct SetFarmingPhRequest {
157152
pub(super) puzzle_hash: Bytes32,

napi/__test__/full_node_simulator.spec.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,29 @@ test("full node simulator includes farmed rewards in block records", (t) => {
7575
t.false(rewardRecord!.spent);
7676
});
7777

78-
test("full node simulator autofarm defaults on and can be toggled", (t) => {
78+
test("full node simulator push tx waits for manual farming", (t) => {
7979
const sim = new FullNodeSimulator();
80-
t.true(sim.getAutofarm());
80+
const clvm = new Clvm();
81+
const puzzle = clvm.parse("1");
82+
const puzzleHash = puzzle.treeHash();
83+
const coin = sim.newCoin(puzzleHash, 100n);
84+
85+
const spendBundle = new SpendBundle(
86+
[
87+
new CoinSpend(
88+
coin,
89+
puzzle.serialize(),
90+
clvm.parse(`((51 0x${Buffer.from(puzzleHash).toString("hex")} 99))`).serialize()
91+
),
92+
],
93+
Signature.infinity()
94+
);
8195

82-
sim.setAutofarm(false);
83-
t.false(sim.getAutofarm());
96+
t.true(sim.pushTx(spendBundle).success);
97+
t.is(sim.getBlockchainState().blockchainState?.mempoolSize, 1);
8498

85-
sim.setAutofarm(true);
86-
t.true(sim.getAutofarm());
99+
sim.farmBlock(1);
100+
t.is(sim.getBlockchainState().blockchainState?.mempoolSize, 0);
87101
});
88102

89103
test("full node simulator can serve rpc over http", async (t) => {
@@ -99,7 +113,6 @@ test("full node simulator can serve rpc over http", async (t) => {
99113
const clvm = new Clvm();
100114
const puzzle = clvm.parse("1");
101115
const puzzleHash = puzzle.treeHash();
102-
sim.setAutofarm(false);
103116
const coin = sim.newCoin(puzzleHash, 100n);
104117

105118
const spendBundle = new SpendBundle(

napi/index.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,8 +1220,6 @@ export declare class FullNodeSimulator {
12201220
getMasterSecretKey(): SecretKey
12211221
getPrefarmPuzzleHash(): Buffer
12221222
setFarmingPh(puzzleHash: Uint8Array): void
1223-
getAutofarm(): boolean
1224-
setAutofarm(autofarm: boolean): void
12251223
getBlockchainState(): BlockchainStateResponse
12261224
getNetworkInfo(): GetNetworkInfoResponse
12271225
getAggsigAdditionalData(): Buffer

napi/src/lib.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,6 @@ impl FullNodeSimulator {
336336
Ok(())
337337
}
338338

339-
#[napi]
340-
pub fn get_autofarm(&self) -> Result<bool> {
341-
Ok(self.inner.get_autofarm()?)
342-
}
343-
344-
#[napi]
345-
pub fn set_autofarm(&mut self, autofarm: bool) -> Result<()> {
346-
self.inner.set_autofarm(autofarm)?;
347-
Ok(())
348-
}
349-
350339
#[napi]
351340
pub fn get_blockchain_state(&self, env: Env) -> Result<BlockchainStateResponse> {
352341
Ok(FromRust::from_rust(

0 commit comments

Comments
 (0)